PHP tmp 文件夹?
我正在练习使用 PHP 上传文件,并且多次上传文件,因此我想确保没有占用服务器上的大量空间。我用 while 循环检查了 php tmp 目录中的每个文件,有 103,988 个条目。
这比正常情况多吗?我假设 tmp 目录用于存放在一段时间后自动删除的文件。我应该如何管理这个文件夹?
我问这个问题的部分原因是因为我正在编写一个应用程序,该应用程序需要用户文件,更改一些内容,然后将其返回给他们。我希望他们离开后删除该文件,但我不确定最好的方法是什么。我是否应该有一个文件夹来放置所有文件并使用 cron 删除早于特定时间的文件?
I'm practicing some file upload with PHP and I was uploading a file numerous times, so I wanted to make sure I wasn't taking up a lot of space on the server. I had a while loop go over every file in the php tmp directory, and there were 103,988 entries.
Is this more than normal? I had assumed the tmp directory was for files that were automatically deleted after a certain amount of time. Am I supposed to be managing this folder some how?
Part of the reason I ask is because I'm writing an app that takes a users file, changes some things, and serves it back to them. I want the file to be deleted once they leave, but I'm not sure what the best way to do it is. Should I have a folder I put all the files in and use cron to delete files older than a certain time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般规则是,您应该尽可能自行清理。
如果您不确定每次是否可以删除临时文件,最好让 cron 作业偶尔为您执行此操作。
General rule is that you should clean up after yourself whenever possible.
If you aren't sure that you can remove temporary files every time, it is a good idea to have a cron job doing this for you once in a while.