无法上传面向Warning:move_uploaded_file的文件

时间:2017-11-07 11:29:14

标签: php mysql file-upload

在这个问题中,我想在php中上传文件但是我无法上传文件而且我收到了这个“警告:move_uploaded”。 enter image description here 我附加了错误屏幕截图。

This is my **uploadhtml.php** file 

<html>
<head>
  <title>Upload your files</title>
</head>
<body>
  <form enctype="multipart/form-data" action="upload.php" method="POST">
    <p>Upload your file</p>
    <input type="file" name="uploaded_file"></input><br />
    <input type="submit" value="Upload"></input>
  </form>
</body>
</html>


This is my **upload.php** file

<?php

  if(!empty($_FILES['uploaded_file']))
  {
    $path = "uploads/";
    $path = $path . basename( $_FILES['uploaded_file']['name']);

    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path))
    {
      echo "The file ".  basename( $_FILES['uploaded_file']['name']). 
      " has been uploaded";
    }

    else
    {
        echo "There was an error uploading the file, please try again!";
    }
  }

?>

1 个答案:

答案 0 :(得分:0)

将您的添加到绝对本地路径。

$path = dirname(__FILE__) . "/uploads/";

所以你的最终$路径就像/var/www/html/project/upload/filename

move_uploaded_file()永远不会创建文件夹,因此您应该自己创建上传文件夹。