PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] How to check if a particular file already exists by using an uploaded file to find a match in PHP

 July 18, 2022     file-upload, gif, match, pattern-matching, php     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing