该签名生成器的最佳解决方案?
嘿!我想知道解决我的问题的最佳方案。 我有一个签名生成器 http://www.anitard.org/siggen/siggen_stripes/人们可以上传自己的签名图像。问题是,如果我没有一个脚本可以在完成签名后删除图像,那么我的存储空间很快就会满。
对此最好的解决方案是什么?
Hey! i want to know the best solution for my problem.
I have a signature generator http://www.anitard.org/siggen/siggen_stripes/ where people can upload their own images for the signature. The problem is that my storage will get full pretty fast if i dont somehow have a script that deletes the images when they are done with the signature.
What is the best solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对此的最初感觉是根本不保存上传的文件,而是在生成图像后立即删除它们。然而,当用户尝试保存图像时,某些浏览器可能会再次请求图像 - 例如,我知道 Firefox 的 DownloadThemAll 扩展就是如此。因此,您可能需要将文件存储很短的时间,就像 @JustLoren 所建议的那样。
在 Google 上快速搜索“php删除临时文件”会发现 至少一个脚本准确解释如何在一段时间后删除文件。这不必作为外部脚本或 cron 作业运行;例如,它只能附加到上传脚本上。
给定脚本中的一个缺陷是有人可以快速连续上传许多文件,超出您的磁盘配额。您可能希望通过删除早于最近 50 个或任意数量的任何文件来扩展链接脚本。为此,只需检查匹配文件的数量,按创建时间排序,然后删除索引大于 50 的文件。
My initial feeling on this would be to not save the uploaded files at all, but to just delete them as soon as the image is generated. However, some browsers might request the image again when the user tries to save the image -- I know this is true with Firefox's DownloadThemAll extension, for instance. So you'll probably have to store the files for a short amount of time, like @JustLoren suggests.
A quick Google search for "php delete temp files" turns up at least one script explaining exactly how to delete files after a certain amount of time. This would not have to be run as an external script or cron job; it could merely be tacked on to the upload script, for instance.
One flaw in the given script is that someone could rapidly upload many files in a row, exceeding your disk quota. You might want to expand on the linked script by deleting any files older than the last 50 or however many. To do that, just check the count of the matched files, sort by creation time, and delete any with index greater than 50.
就我个人而言,我会有一个每小时(或每天,取决于卷)运行的脚本来检查文件的创建日期,如果时间超过一小时则将其删除。实际上,用户应该在创建图像后 2 分钟内将图像保存到硬盘上,但你不能指望它。一个小时似乎是一个不错的妥协。
Personally, I would have a script that runs every hour (or day, depending on volume) that checks the file's creation date and deletes it if the time is over an hour old. Realistically, users should save their images to their harddrives within 2 minutes of creating them, but you can't count on it. An hour seems like a nice compromise.