PHP上传文件错误

时间:2011-08-06 15:52:29

标签: php

我尝试使用PHP将照片上传到我的服务器,但脚本总是转到else语句,我无法解决原因。

if (isset($_POST['submit'])) {

$image=($_FILES['image']['name']);
$target = "../../portfolio/photos";
$target = $target . basename( $_FILES['image']['name']);


if(move_uploaded_file($_FILES['image']['name'], $target))
{
    $sql_addProduct = "INSERT INTO photos (img_url) VALUES '$image'";
    $queryresult_add = mysql_query($sql_addProduct);

    echo "The file ". basename( $_FILES['image']['name']). " has been uploaded succesfully";
}
else {
    //Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}}

任何人都可以解释这个问题吗?

2 个答案:

答案 0 :(得分:4)

move_uploaded_file($_FILES['image']['name']

应该是:

move_uploaded_file($_FILES['image']['tmp_name']

答案 1 :(得分:0)

检查$_FILES["image"]["error"]文件是否正确上传。 然后检查它是否是getimagesize($_FILES["image"]["tmp_name"]);的图像可能是有用的(并且更安全)。然后你可以移动它 move_uploaded_file($_FILES["image"]["tmp_name"], $target); 如果它仍然无法正常工作,请检查目录是否可写is_writable($target);