TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-19-2009, 10:43 AM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default 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.
__________________
Tanax is offline  
Reply With Quote
Old 08-19-2009, 10:54 AM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.)?
Salathe is offline  
Reply With Quote
Old 08-19-2009, 12:00 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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.
__________________
Tanax is offline  
Reply With Quote
Old 08-19-2009, 12:13 PM   #4 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 11
Thanks: 1
jasonberresford is on a distinguished road
Default

<?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. :)
jasonberresford is offline  
Reply With Quote
The Following User Says Thank You to jasonberresford For This Useful Post:
Tanax (08-19-2009)
Old 08-19-2009, 03:14 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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..
__________________
Tanax is offline  
Reply With Quote
Old 08-19-2009, 03:22 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
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.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Tanax (08-19-2009)
Old 08-19-2009, 04:20 PM   #7 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
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.
__________________

Village Idiot is offline  
Reply With Quote
Old 08-19-2009, 05:15 PM   #8 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Old 08-19-2009, 07:04 PM   #9 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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() ?
__________________
Tanax is offline  
Reply With Quote
Old 08-19-2009, 07:14 PM   #10 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 11
Thanks: 1
jasonberresford is on a distinguished road
Default

Yes it's just fine, because any changes to that image would result in a different MD5
jasonberresford is offline  
Reply With Quote
Old 08-19-2009, 07:26 PM   #11 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
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.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-19-2009, 08:49 PM   #12 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by jasonberresford View Post
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? ^_^
__________________
Tanax is offline  
Reply With Quote
Old 08-19-2009, 08:55 PM   #13 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
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 )
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-19-2009, 09:53 PM   #14 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Great, thanks everyone!
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:45 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design