TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   ImageGD (http://www.talkphp.com/advanced-php-programming/4873-imagegd.html)

Tanax 08-19-2009 10:43 AM

ImageGD
 
Hey!

I'm just wondering.. is it possible to check if 1 image is the same as another image? So I can prevent members from uploading the same image several times.

Salathe 08-19-2009 10:54 AM

You could just take an MD5 hash of each file and if they are literally the same image then the hashes will match. Or are you wanting to cater for different copies of the same image (sizes, file types, etc.)?

Tanax 08-19-2009 12:00 PM

I didn't understand the part "cater for different copies" - my english vocabulary is not perfect.

Anyhow, what I want is that I want them to only be able to upload the same image ONCE. However, if they for example crop the image, the image won't be the same(though the object will probably be the same - but it's not the same image), they will be able to upload that.

What I mean is basically I want to run a check if they already uploaded the FILE once before. But since they can change the filename in the case - using the filename is not the best option for me.. if you understand what I mean?

I really hope I'm explaining this so you understand.

jasonberresford 08-19-2009 12:13 PM

<?php
$file = 'image.jpg';
$filemd5 = md5_file($file);

When inserting the image, insert with the md5 .. when a new image is inserted check the database for the existing md5.. if it's not there .. insert, if it is .. don't. :)

Tanax 08-19-2009 03:14 PM

Yes, I understood that part. Problem with that is if they change the name of the file, they will be able to upload the exact same image, only it's another name..

Salathe 08-19-2009 03:22 PM

Quote:

Originally Posted by Tanax (Post 27941)
Yes, I understood that part. Problem with that is if they change the name of the file, they will be able to upload the exact same image, only it's another name..

No, the function used is md5_file which creates an MD5 hash of the binary contents of the file, not the file name.

Village Idiot 08-19-2009 04:20 PM

Quote:

Originally Posted by Tanax (Post 27924)
I didn't understand the part "cater for different copies" - my english vocabulary is not perfect.

Don't feel bad, I have no idea what that meant either.

Salathe 08-19-2009 05:15 PM

By "different copies" I quite simply mean the same image but saved at slightly different sizes, crops, file formats, quality settings, etc.. That's a little trickier than looking for exact file matches.

"To cater for/to" is a turn of phrase, I've no idea how widespread its use is.

Tanax 08-19-2009 07:04 PM

Thanks alot!

One question though. I want people like.. they should be able to upload a original photo, and then if they use some filters or effects on that photo in .. for instance Photoshop, they should be able to upload that edited picture. That is still possible if I use the md5_file() ?

jasonberresford 08-19-2009 07:14 PM

Yes it's just fine, because any changes to that image would result in a different MD5

Enfernikus 08-19-2009 07:26 PM

Quote:

Originally Posted by Salathe (Post 27951)
By "different copies" I quite simply mean the same image but saved at slightly different sizes, crops, file formats, quality settings, etc.. That's a little trickier than looking for exact file matches.

"To cater for/to" is a turn of phrase, I've no idea how widespread its use is.

Extremely.

Tanax 08-19-2009 08:49 PM

Quote:

Originally Posted by jasonberresford (Post 27961)
Yes it's just fine, because any changes to that image would result in a different MD5

Right.. that's great :-)
But if they only change the name of the file, it will still have the same MD5 hash, right? ^_^

Enfernikus 08-19-2009 08:55 PM

Quote:

Originally Posted by Tanax (Post 27964)
Right.. that's great :-)
But if they only change the name of the file, it will still have the same MD5 hash, right? ^_^

Yup. ( Char Limit )

Tanax 08-19-2009 09:53 PM

Great, thanks everyone!


All times are GMT. The time now is 09:42 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0