Re: crc check for JPEG file exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Olav Mørkrid wrote:
hello

is crc32() an acceptable way of managing whether a JPEG file exists
(in a database or similar collection)?

i mean doing a crc32() on the binary data of the JPEG file, and then
check the database if there is already another entry with the same
CRC.

the database has relatively few images (some thousands).

is there any chance of collision (two different JPEG images generating
the same CRC) that is anywhere near likely, or is this extremely
remote?

advice would be appreciated.
Hello,

I suggest you put the md5 result in de DB, so you only have to create one md5 on request and compare that one with the DB result. You can put an index on that field as well, for speed.

On a filesystem I would make the md5 hash part of the path/filename of the JPEG. Or make a symlink from the hash to the image path. This makes lookup much faster since you spread the load of computing the md5 over time. Doing two md5 calculations for each file to match is intensive.

So instead of doing:

$file1 = file_1.jpg
$file2 = file_2.jpg

if (md5($file1) === md5($file2)) {
...
}

You better do (something like it):

$hash = md5($file);

if (file_exists('image_'.$hash.'.jpg')) {
.....
}


Just my thoughts.

Kind regards,

Aschwin Wesselius

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux