Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP File Upload, files disappearing from /tmp before move_uploaded_files

I have a very basic upload script, probably lifted straight off the php.net/move_upload_files function page.

move_uploaded_file() is failed because it cannot find the tmp file in the tmp folder. But I KNOW that it is being put there, but is removed before move_upload_file() can deal with it in my script. I know it is being put there since I can see a file in there when a large file is being posted to the server.

Also $_FILEScontains correct details for the file I have just uploaded.

Had anyone have any idea why the temporary file is being removed from /tmp before I have a chance to handle it?

Here is the basic code that I am using.

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_file))
{
    $result['error'] = 'false';
    $result['file_loc'] = $upload_file;
}
else
{
    $result['error'] = 'true';
}

The output of print_r($_FILES) looks like

[userfile] => Array
(
    [name] => switchsolo.png
    [type] => image/png
    [tmp_name] => /tmp/phpIyKRl5
    [error] => 0
    [size] => 6690
)

But /tmp/phpIyKRl5 simply isn't there.

like image 505
Bowen Avatar asked Nov 30 '09 12:11

Bowen


1 Answers

1) Are the post_max_size and upload_max_filesize holding higher value than the size of the file you are trying to upload?

2) Does your uploading script take longer time to execute than the value of the max_execution_time variable allows?

3) I assume your uploading script doesn't consume as much memory as the memory_limit variable allows. When the client is uploading the file to the server, then the server is probably holding some of it in memory while doing so. I'm not sure if it somehow affects the limit of the memory_limit variable in php.ini.

These variables can be changed in php.ini and/or .htaccess or with ini_set().

Hope that helps.

like image 184
Kristinn Örn Sigurðsson Avatar answered Oct 21 '22 12:10

Kristinn Örn Sigurðsson