The Little Guy Posted April 3, 2012 Share Posted April 3, 2012 lets say I own a file, and you own a file, both these files are the exact same file, the only difference is the filename. So lets say we both have The Gimp 2.6 but one is named TG2.6.exe and the other is named the_Gimp-2.6.exe. What would be the best way to count the files that are the same even if they have a different file name? Another example would be: I have a file called me.jpg and someone else has a file me.jpg but they are two completely different pictures. What would I do to tell that? Quote Link to comment https://forums.phpfreaks.com/topic/260275-how-many-files-are-the-same/ Share on other sites More sharing options...
batwimp Posted April 3, 2012 Share Posted April 3, 2012 Calculate the md5 has of both files and compare them: http://us3.php.net/manual/en/function.md5-file.php Read the comments on that page for more efficient ways to compare large files. Quote Link to comment https://forums.phpfreaks.com/topic/260275-how-many-files-are-the-same/#findComment-1334018 Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2012 Share Posted April 3, 2012 filesize md5_file Files that are the same size, might be the same. Files that are not the same size cannot be the same. Files that have the same md5 hash/checksum, are likely to be the same. Files that don't have the same md5 hash cannot be the same. If files are the same size and have the same md5 hash, you would need to compare byte-byte to determine if they are the same or not. Quote Link to comment https://forums.phpfreaks.com/topic/260275-how-many-files-are-the-same/#findComment-1334019 Share on other sites More sharing options...
The Little Guy Posted April 3, 2012 Author Share Posted April 3, 2012 so, something like this (pre-calculated data)... select *, count(*) total from filedata where /* Search parameters here */ group by filesize, checksum Quote Link to comment https://forums.phpfreaks.com/topic/260275-how-many-files-are-the-same/#findComment-1334089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.