0

//这是一个示例文件上传。它在我的本地主机中运行良好,但在 Intranet 中无法运行.. //这是我的代码

<?php require_once "../session.php" ?>
<?php
$host='localhost'; // My hostname
$username='root'; // Mysql username
$password='*******'; // Mysql password
$db_name='jobs'; // DB name

// Connect to server and select database.
mysql_connect($host, $username, $password)or die("Cannot Connect");
mysql_select_db($db_name);

// Where the file is going to be placed 
$TARGET_PATH = "uploads/";
// Get our POSTed variables
$uploadedfile = $_FILES['uploadedfile'];
// Sanitize our inputs
$uploadedfile['name'] = mysql_real_escape_string($uploadedfile['name']);

// Build our target path full string.  This is where the file will be moved do
// i.e.  images/picture.jpg
$TARGET_PATH .= $uploadedfile['name'];

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if (move_uploaded_file($uploadedfile['tmp_name'], $TARGET_PATH))
{
    $sql = "update personal set resume='" . $uploadedfile['name'] . "' where username='".$_SESSION['name']."'";
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
    header("Location: ../scripts/view.php");
    exit;
}
else
    {
        echo "There was an error uploading the file, please try again!";
    }

?>

这仅适用于我的电脑(使用 wamp 的本地主机)。:((

4

2 回答 2

0

确保对uploads/文件夹具有适当的权限。使用 Filezilla 进行配置。

于 2012-08-02T03:32:57.973 回答
0

我已经检查了我的服务器它的工作正常我认为上传目录的权限问题或者可能是上传目录的路径错误。

<html>
<body>

<form action="fileupload.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="uploadedfile" id="uploadedfile" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html> 

//你的php代码

<?php require_once "../session.php" ?>
<?php
$host='localhost'; // My hostname
$username='root'; // Mysql username
$password=''; // Mysql password
$db_name='blog'; // DB name

// Connect to server and select database.
mysql_connect($host, $username, $password)or die("Cannot Connect");
mysql_select_db($db_name);

// Where the file is going to be placed 
$TARGET_PATH = "uploads/";
// Get our POSTed variables
$uploadedfile = $_FILES['uploadedfile'];
// Sanitize our inputs
$uploadedfile['name'] = mysql_real_escape_string($uploadedfile['name']);

// Build our target path full string.  This is where the file will be moved do
// i.e.  images/picture.jpg
$TARGET_PATH .= $uploadedfile['name'];

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if (move_uploaded_file($uploadedfile['tmp_name'], $TARGET_PATH))
{
    echo $sql = "update personal set resume='" . $uploadedfile['name'] . "' where username='".$_SESSION['name']."'";
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
    header("Location: ../scripts/view.php");
    exit;
}
else
    {
        echo "There was an error uploading the file, please try again!";
    }

?>
于 2012-08-02T03:39:00.093 回答