适合处理大量文件上传的技术
我在一个每天从用户那里收到大约 500 张照片上传的网站工作。尽管这并不是一个很高的数字,但我们正在经历不同上传之间的一些冲突。一些用户报告说看到的是另一张图片的缩略图,而不是他们上传的图片。我一直在寻找这个问题的解释,并且在 stackoverflow 中发现了几个问题:
正如我所读到的,该问题似乎与文件 tmp 名称中的冲突有关。为了避免这种情况,我们正在考虑根据记录的用户名计算出的整数来更改 upload_tmp_dir
PHP 变量,以减少冲突概率。然而,这个变量在运行时是不可更改的,因为当 PHP 开始执行时,文件已经发布到服务器。
我不确定如何解决这个问题,我想修复它,以防止日上传率不断增加时出现未来问题。
有很多网站可以处理大量上传,所以我想知道如何避免这种冲突问题。我正在工作的网站运行 PHP 5.2.14。为了简单起见,我更喜欢 PHP 解决方案,但我也对使用其他脚本语言的现有解决方案感兴趣,只要它们保证上传之间不会发生冲突。
I am working in a site that receives about 500 photo uploads per day from its users. Although this is not a really high number, we are experiencing some collisions between different uploads. Some users have reported seeing the thumbnail of another picture instead of the one that they have uploaded. I have been looking for an explanation of this problem, and I have found a couple of questions in stackoverflow:
PHP temp file names for uploads colliding
PHP file uploads being "hijacked" by partial uploads
As I have read, the problem seems to be related to a collision in the file tmp name. In order to avoid that, we were considering to change the upload_tmp_dir
PHP variable depeding on an integer calculated from the logged username in order to reduce the collision probability. However, this variable is not changeable at runtime, as when PHP starts to execute, the file is already posted to the server.
I am not sure about how to solve this issue, and I would like to fix it in order to prevent future problems if the daily upload rate keeps increasing.
There are many sites that handle large volumes of uploads, so I wonder how this collision problem is avoided. The site I am working in runs on PHP 5.2.14. I would prefer a PHP solution for simplicity, but I amb also interested in existing solutions that use other scripting languages, as long as they guarantee that no collisions happen between uploads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题也可能出在您的 DBlogic 中。一种安全的方法是将一行插入数据库,获取记录的主键。使用该数字作为文件名可以防止冲突。您可以执行以下操作:
然后获得您的 (auto_increment) id。您可以保存其余数据(例如标签到不同的表)并处理您的文件,并且名称不会冲突。
The problem can also lie in your DBlogic. A safe way is to insert a row to the DB, get the primary key of your record. Using that number as the filename will prevent collisions. You can do something like:
Then have your (auto_increment) id. You can save the rest of your data (tags for example to different table) and process your file and the names won't collide.