A suitable technology for handling a large number of file uploads
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 pr开发者_如何学Coblem, 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.
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:
LOCK TABLES image WRITE;
INSERT INTO image (id) VALUES (NULL);
SELECT LAST_INSERT_ID();
UNLOCK TABLES;
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.
精彩评论