Re: Dupe file check using MD5?

From: Date: Fri, 28 Jul 2000 02:25:07 +0000
Subject: Re: Dupe file check using MD5?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-8699@lists.php.net to get a copy of this message
You *could* just read in the whole file into one string, run md5 on it and compare that to the data on the file you have stored in the database. Even better, you could store the md5 for the file in the database in another field, and then you wouldn't have to rerun it each time you need to compare it to the database. However, depending on the size of the files you are working with, this may not be an ideal soution. (as reading a 5MB into memory to run an md5 hash on it probably isn't a real good use of memory.) Instead, you could consider reading the first 1024 bytes from the file and maybe the last 1024 bytes into a string and hashing that. More than likely, if you're working with binary files (especially images) this would be able to spot any changes that were made to the file. You might, also, consider including the size of the file in the hash somewhere, which would more than likely cover any changes missed by the first 1024 bytes and the last 1024 bytes. There is the potential that this would not be 100% accurate, but it would probably work more often then not. Keep in mind, however, that reading the last part of a large file is likely to be disk intensive. P.S. If you think 1K is too small, you could always up that to do the first 4K and last 4K or some other size which you deem is more appropriate. Hope this helps, - Ben Schumacher At 09:49 PM 7/27/00 -0400, Some Guy wrote:
Ed said:
and you want to make an MD5 hash of the whole file, or just the > filename?
And as I said I want to hash the whole file and use that MD5 to compare to a hash of the whole uploaded file. If I only wanted to do it on the name that would be a variable and make the whole point of my question moot, I wouldnt even have to md5 to compare the name. I want to generate a md5 key from the whole contents of a file to compare to a list of already uploaded files that I have already run the md5 function on. Like I said I know about the MD5 function but the function only takes a variable not a file. Hence my problem and my question. Is that a little clearer?
I have an upload script. I would like to compare a file uploaded with a data base entry for dupes. I thought I could use the md5 function to generate a hash of each file and enter it in a database but the md5 function takes a variable not a file.
________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.general (#8699) next »