Issue
giphy.com, during an upload, somehow recognizes if a particular GIF animation has already been uploaded to their servers. and I was wondering how I can replicate that using PHP in a very efficient (low-server intensive) manner?
The only way I can think of doing this is by looping between all the files on my server (which I would think would be a highly server intensive task) and trying to find a match (and by match, I don't mean filename; I mean if the exact same gif was uploaded (the exact file regardless of the filename)).
But I'm not too sure of what particular PHP functions I'd have to use.
Solution
Use a database. At each upload you calculate a md5 hash of the file ( using md5_file ) and you store that in the database. Looking up the database to see if the hash already exists will be very fast.
Answered By - Lorenz Meyer Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.