Reputation: 2716
This sounds like a stupid question but, after uploading a file the file isnt in the location php said it would be.
First the 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, the print_r in plain text:
Array ( [imgup] => Array ( [name] => ace.jpg [type] => image/jpeg [tmp_name] => /tmp/phpEdfBjs [error] => 0 [size] => 29737 ) )
So no error, standard looking path, but /tmp has no such file. Further, running a find on my whole system turns up bubkis.
FYI: php.ini has
max_execution_time = 120
file_uploads = On
upload_max_filesize = 2M
and the file I've been uploading is 29k
Any thoughts?
Upvotes: 13
Views: 28499
Reputation: 401172
The temporary file is deleted when the PHP script that received it has finished running : it is just a temporary file.
The PHP script to which you are posting the form -- upload.php -- should move the temporary file to a non-temporary location, using move_uploaded_file()
Basically, the idea is :
If the upload doesn't finish successfully, or if you don't move the file somewhere else, the temporary file is automatically deleted.
As a reference, you should read the following section of the manual : Handling file uploads - POST method uploads
Quoting the part of it which 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 away or renamed.
Upvotes: 24