PHP:什么时候临时上传的文件被删除? [英] PHP: When does the temporary uploaded files get deleted?
问题描述
$ b $ p $ $ FILES [tmp_name] =>字符串'C:\wamp\tmp\phpD382.tmp'(长度= 23)
我去那个文件夹,它是空。我确定我的显示隐藏文件是从我的文件夹选项,但我没有看到它。它到底在哪里?
除了什么时候被删除呢?如果我不移动那个文件?例如,如果我正在上传文件,并且文件上传到了一半,我决定关闭浏览器,文件会发生什么变化?什么时候服务器知道要删除临时文件?
只要您的PHP脚本完成执行并重新保存到定义位置
使用直接PHP,无框架的示例
http://www.php.net/manual/en/features.file-upload.post-method.php
$ uploaddir ='/ var / www / uploads /';
$ uploadfile = $ uploaddir。基名($ _ FILES [ userfile的] [名称]);
echo'< pre>';
if(move_uploaded_file($ _ FILES ['userfile'] ['tmp_name'],$ uploadfile)){
echo文件有效,已成功上传。
} else {
echo可能的文件上传攻击!\\\
;
}
echo'这是一些更多的调试信息:';
print_r($ _ FILES);
打印< / pre>;
?>
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?
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>";
?>
这篇关于PHP:什么时候临时上传的文件被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!