上传的文件在您的服务器上保留多长时间?
当我使用表单上传文件时,它会给我“名称”和“tmp_name”,您应该将文件从其临时位置移动以保留它。但是文件在被删除之前会在服务器上保留多长时间?它是永久存储在那里直到您手动清理文件夹,还是在提交的 PHP 脚本完成运行后被删除?我的表单跨越多个页面,我想在最后处理所有内容,而不是在表单的每一页完成后处理部分内容。上传是在第 3 步(共 5 步)中,所以我想知道我是否保存了第 3 步中上传的文件信息,当第 5 步完成表单后该文件是否仍然存在。
When I use a form to upload a file, it gives me the 'name' and 'tmp_name' and you're supposed to move the file from its temporary location in order to keep it. But how long does the file stay on the server before it gets deleted? Is it stored there permanently until you manually clean up your folders, or does it get deleted once the PHP script it was submitted too is finished running? My form spans over multiple pages and I wanted to just process everything at the end rather than processing parts after each page of the form is completed. The upload is in step 3 of 5 so I was wondering if I saved the uploaded file information from step 3, if the file would still be there when the form is finished after step 5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非 PHP 死于可怕的火灾,或者您采取措施保留该文件,否则当脚本退出时,它会被 PHP 自动杀死。如果您需要通过多阶段表单保留它,则必须将其移动到安全的地方,然后跟踪它(隐藏表单字段、会话、数据库等)并实现您自己的清理系统处理废弃表单中的孤立文件。
Unless PHP dies a horrible flaming death, or you take steps to preserve the file, it'll be auto-killed by PHP when the script exits. If you need to preserve it through a multi-stage form, you'll have to move it somewhere safe, and then keep track of it (hidden form fields, session, database, etc...) and implement your own cleanup system to handle orphaned files from abandoned forms.
一旦提交的 PHP 脚本完成运行,它就会被删除,
因此,您可以将文件上传作为最后一步,或者为未完成的表单实现您自己的垃圾收集器。
it get deleted once the PHP script it was submitted too is finished running
so, you can either make file upload as last step or implement your own garbage collector for the unfinished forms.
这取决于 tmp 上传文件夹。如果它是
tmp
目录,您就不能真正相信它能够活到第 5 步。如果您控制上传文件夹,那么您可以可靠地相信它能够活到第 5 步。您可以设置上传路径为upload_tmp_dir
It depends on the tmp upload folder. If it is the
tmp
directory, you can't really trust it to live to step 5. If you control the upload folder, then you could reliably trust it to live to step 5. You can set the upload path withupload_tmp_dir