简体   繁体   中英

php uploaded file does not exist

I've made sure that the /tmp folder is writeable, and in php.ini

upload_max_filesize = 5M
post_max_size = 8M

and in my upload.html

<html>
<body>

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

</body>
</html>

and in my upload_file.php

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  move_uploaded_file ($_FILES["file"]["tmp_name"] , '/var/www/html/web' );
  }
?> 

This is the output

Upload: screenshot 2013-12-30 15:00:54.png
Type: image/png
Size: 201.8154296875 kB
Stored in: /tmp/phpEdIgXr 

but /tmp/phpEdIgXr does not exist!

Just put below code and try. it might be helpful to you.

if ($_FILES["file"]["error"] > 0)
    {
        echo "Apologies, an error has occurred.";
        echo "Error Code: " . $_FILES["file"]["error"];
    }
    else
    {
        move_uploaded_file($_FILES["file"]["tmp_name"],"[YOUR FOLDER PATH]".$_FILES["file"]["name"]); 
    }

对于任何上传到目录中的文件,您需要chmod 777该文件夹。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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