Downloading a file not to / tmp

This sounds like a dumb question, but after downloading the file, the file is not in the place where php said it would be.

First a simple test page:

<html><body> <h1><?=$_FILES['imgup']['tmp_name'];?></h1> <? print_r($_FILES); ?> <form enctype="multipart/form-data" method="post" action="upload.php"> <input type="file" name="imgup" id="imgup"> <input type="submit"> </form> </body></html> 

Now, print_r is in plain text:

 Array ( [imgup] => Array ( [name] => ace.jpg [type] => image/jpeg [tmp_name] => /tmp/phpEdfBjs [error] => 0 [size] => 29737 ) ) 

Thus, no error, the standard search path, but / tmp does not have such a file. In addition, when starting a search, bubbles appear on my entire system.

FYI: php.ini has

 max_execution_time = 120 file_uploads = On upload_max_filesize = 2M 

and the file I uploaded is 29k

Any thoughts?

+7
source share
1 answer

The temporary file is deleted when the PHP script that received it exits: it is just a temporary file.

The PHP script you submit the form to - upload.php - should move the temporary file to a non-temporary location using move_uploaded_file()


Basically, the idea is this:

  • The user uploads the file to your script,
    • This file is stored in temporary lcoation.
  • Your script works in this file:
    • Checks if the file is OK (content type, size, ...)
  • And if the file is ok, your script moves it to the repository's permanent directory (wherever you want)

If the download did not complete successfully, or if you do not move the file to another location, the temporary file is automatically deleted.


As a reference, you should read the following section of the manual: Processing file downloads - loading POST files

Quoting the part that is related to your problem:

The file will be deleted from the temporary directory at the end of the request if it has not been moved or renamed.

+16
source

All Articles