开发者

Php file uploads and prevent duplicates

开发者 https://www.devze.com 2023-04-04 00:40 出处:网络
I would like to create an upload form with php. The problem is that it will be used to upload a fixed row length text file that would contain orders. (full order details would be duplicated for each r

I would like to create an upload form with php. The problem is that it will be used to upload a fixed row length text file that would contain orders. (full order details would be duplicated for each row).

Then it should place the file somewhere and call a program that will read the file and place the orders. The problem is that i want to prevent the same order file to be sent to the order program.

The file wont have any unique identifier. I am wondering which is the best way to check that the file isnt the same. One solution is to calculate MD5 for each file and store them but i am not sure about concurency and whether this would work and how many files to compare with.

THe开发者_运维知识库 only solution i can figure out it to store some max(20) for example to a file and use flock() for this file to avoid concurency problems. Like program A checks if file exists via md5,program B checks if file exists via md5 (they may from a a non updated thats why i think i should use exclusive lock.... Any other solution ?


Store the MD5 hash (or SHA1) and size of the file in the database. Index the hash.

To check for duplicates, just search in the database for a file with the same hash and size.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号