Jump to content

Way to tell if an uploaded file matches file on server without same file name


anolan13

Recommended Posts

Hello,

 

I need a way where if users upload a file to my server that's the same as another file (both .mp3 files) but don't necessarily have the same filename, the server will know and perform an action based on this.

 

Is there a way for PHP to check certain characteristics in an mp3 file that would make it different from another file or the same as another file regardless of the file name?

 

 

Just a quick example,

These two files are the same but have different file names...

 

mysong1.mp3

thebestsongever.mp3

 

Is there a way for the server to tell the difference or similarity once their both uploaded?

 

Thanks,

No. It will match if both files generate same md5(). There is very low probability, that two different files will generate the same md5() (situation called collision). To reduce risk of collisions, one may use hash with some other hashing algorithm, but I think in this case md5() should be sufficient.

 

The best would be to calculate md5 whenever a file is uploaded and compare it against hashes of previously uploaded files (preferably stored in database).

 

Wouldn't you have to use md5_file() ??

 

That would be actually easier than loading a file into string :P

 

There's also hash_file

I would compare file sizes and the md5/checksum. Files that are different sizes cannot be the same. This will further reduce the chance of different files having the same md5/checksum.

I think I'd just compare hashes generated by some other function... Probability that there's collision of md5 hashes is low already, and probability that both md5 and sha1 (or something) hashes are the same is like... nil[1].

 

And I can hardly see anyone manipulating a file so that he can not upload it :P

 

 

 

[1] nil is not zero, but close enough

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.