简体   繁体   English

php图片上传无法将实际文件复制到目标文件夹

[英]php image upload cant copy the actual file to the destination folder

I am having a problem when trying to upload an image to my mysql database which has 3 fields: id(auto increment), username and image location. 我在尝试将图像上传到我的mysql数据库时遇到问题,该数据库有3个字段:id(自动增量),用户名和图像位置。 The code is only inserting the image location to the database but not copying the actual image to the "profile_pics" directory. 代码仅将图像位置插入数据库,但不将实际图像复制到“profile_pics”目录。 Please assist. 请协助。

This is my code: 这是我的代码:

<?php

$connection=mysql_connect("localhost", "root", "");
$choose_db=mysql_select_db("ninjacity", $connection) or die (mysql_error());

if ($_SESSION['user'] && $_POST['submit'])
{
    function check() // to check if the pic already exists
    {
        $username=$_SESSION['user'];
        $choose_db;
        $sql_check="SELECT * FROM profile_pics WHERE username='$username'";
        $res_check=mysql_query($sql_check) or die (mysql_error());
        return mysql_num_rows($res_check);
    }

    $name=$_FILES['image']['name'];
    $tmp_name=$_FILES['image']['tmp_name'];


        $check=check();
        if ($check==1)
        {
            echo "You already have a profile pic. IF you wish to change it, please use the 'Edit my Profile' section";
        }
        else
        {
            $name;
            $tmp_name;
            $username=$_SESSION['user'];
            $location="profile_pics/$name";
            move_uploaded_file($tmp_name, "profile_pics/".$name);

            $choose_db;
            $sql="INSERT INTO profile_pics VALUES ('$_POST[id]', '$username', '$location')";
            $res=mysql_query($sql) or die (mysql_error());
            print "Image successfully uploaded";
        }

}
else
{
    echo "Please fill all fields";
}


?>

Have you checked the permission of the profile_pics directory . 您是否检查了profile_pics目录的权限。 It should be 777. 它应该是777。

Or the issue related to the path (destination path of your directory )you have used in move_uploaded_file . 或者与您在move_uploaded_file中使用的路径(目录的目标路径)相关的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM