PHP: When does the temporary uploaded files get de

2019-01-23 01:13发布

I am running WAMP server. On file upload using PHP I see

$_FILES[tmp_name] => string 'C:\wamp\tmp\phpD382.tmp' (length=23)

I go to that folder and it's empty. I made sure my 'show hidden files' is on from my 'folders option' but I don't see it. Where is it exactly?

Besides when does it get deleted? If I don't move that file? For an instance if I'm uploading a file and the file uploaded halfway and I decided to close that browser what happens to the file? When does the server know to delete that temp file?

3条回答
叛逆
2楼-- · 2019-01-23 01:27

If deleting file is not desired, i found that PHP wont delete file after execution if you "move" it to same location.

move_uploaded_file($temporaryFile, $temporaryFile);
查看更多
ら.Afraid
3楼-- · 2019-01-23 01:28

If you do not do anything with them they will be deleted right after the script is finished.

查看更多
干净又极端
4楼-- · 2019-01-23 01:36

As soon as your PHP script finishes executing and re-saving to the defined location

Example using straight PHP, no framework

http://www.php.net/manual/en/features.file-upload.post-method.php

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>
查看更多
登录 后发表回答