我可以将文件夹路径插入数据库,但图片文件似乎没有移动到该文件夹中?

$pic = $_POST['pic'];

$picName= $_FILES['pic']['name'];

$type = $_FILES['pic']['type'];

$tmp = $_FILES['pic']['tmp'];

$picPath = "/pictures/";

  if(is_uploaded_file($tmp)) {
        if(move_uploaded_file($tmp, $picPath . $picName)) {
            echo "congrats! Image is uploaded.";
        }
        else {
            echo "Sorry, couldn't move your picture.";
        }
    }
    else {
        echo "Sorry, couldn't upload your picture.";
    }

$picPath = $picPath . $picName;

mysql_query("INSERT INTO User(pic) VALUES ('$picPath')");

我收到回音消息:抱歉,无法上载您的图片。
php文件保存在public_html文件夹中,我有一个pictures文件夹,希望将用户的图片移到其中。
插入的工作原理是我可以将$picPath存储在数据库中,但图片不会存储在我的文件夹中。

最佳答案

尝试替换

$tmp = $_FILES['pic']['tmp'];

具有
$tmp = $_FILES['pic']['tmp_name'];

08-19 16:35