4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: V@no on September 10, 2006, 02:50:33 AM

Title: [MOD] Check for duplicate images v1.0
Post by: V@no on September 10, 2006, 02:50:33 AM
This is a very simple check if a uploaded file was previously uploaded.
The method used in this mod is to generate MD5 hash for each image in the database and then compare them with MD5 hash of newly uploaded files.
The name, filename and extension is ignored by this mod, the contents of the file is what used to generate MD5 hash. Though this method has a weak spot: if a file was altered in any way the MD5 hash will be different from the original file.


----------[ Installation ]------------

Step 1
Download this (http://gallery.vano.org/file71dl) package. (File attached on bottom of this post too)
Extract it and upload image_md5_hash.php file into admin/plugins/ folder (if no such folder exists then create it)


Step 2
Open member.php
Find:
Code: [Select]
  if (!$error) {
    // Start Upload
    include(ROOT_PATH.'includes/upload.php');
Insert above:
Code: [Select]
/*
  MOD CHECK FOR DUPLICATE IMAGES
  START INSERT
*/
##########
# CONFIG #
##########

  $check_admin = true; //do check when administrator is uploading? (true/false)
  $show_image = true; //show link to the image that was previously uploaded? (true/false)
  $show_member = true; //show name and link to profile page of the member who previously uploaded that file? (true/false)

##############
# END CONFIG #
##############

  $md5 = "";
  unset($HTTP_POST_VARS['image_md5']);
  if ($user_info['user_level'] != ADMIN || $check_admin)
  {
    if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none")
    {
      $md5 = md5_file($HTTP_POST_FILES['media_file']['tmp_name']);
      $file = $HTTP_POST_FILES['media_file']['filename'];
    }
    elseif ($remote_media_file)
    {
      $md5 = md5($remote_media_file);
      $file = $remote_media_file;
    }
    if ($md5)
    {
      $sql = "SELECT image_id, image_name, cat_id, user_id
              FROM ".IMAGES_TABLE."
              WHERE image_md5 = '".$md5."'
              LIMIT 1";
      if ($row = $site_db->query_firstrow($sql))
      {

        $row['image_name'] = stripslashes($row['image_name']);
        if (function_exists('multilang')) $row['image_name'] = multilang($row['image_name']);
        $user_row = get_user_info($row['user_id']);
//        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$file."</b><br />";
        $msg .= (($msg != "") ? "<br />" : "").(($user_info['user_level'] > GUEST && $user_info['user_id'] == $user_row['user_id']) ? $lang['image_md5_duplicate_self'] : sprintf(($show_member ? $lang['image_md5_duplicate_more'] : $lang['image_md5_duplicate_simple']), "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$user_row['user_id'])."\">".$user_row['user_name']."</a>"));
        if ($show_image && (($user_info['user_level'] > GUEST && $user_info['user_id'] != $user_row['user_id']) || (check_permission("auth_viewcat", $row['cat_id'] && check_permission("auth_viewimage", $row['cat_id'])))))
        {
          $msg .= ": <a href=\"".$site_sess->url(ROOT_PATH."details.php?image_id=".$row['image_id'])."\">".$row['image_name']."</a>";
        }
        $error = 1;
      }
      else
      {
        $sql = "SELECT image_id, image_name, user_id
                FROM ".IMAGES_TEMP_TABLE."
                WHERE image_md5 = '".$md5."'
                LIMIT 1";
        if ($row = $site_db->query_firstrow($sql))
        {
          $user_row = get_user_info($row['user_id']);
//          $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$file."</b><br />";
          $msg .= (($msg != "") ? "<br />" : "").(($user_info['user_level'] > GUEST && $user_info['user_id'] == $row['user_id']) ? $lang['image_md5_duplicate_validation_self'] : sprintf(($show_member ? $lang['image_md5_duplicate_validation_more'] : $lang['image_md5_duplicate_validation_simple']), "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$user_row['user_id'])."\">".$user_row['user_name']."</a>"));
          $error = 1;
        }
      }
      $HTTP_POST_VARS['image_md5'] = $md5;
    }
  }
/*
  MOD CHECK FOR DUPLICATE IMAGES
  END INSERT
*/


Step 3
Open lang/<your language>/main.php
At the end, above closing ?> insert:

:flag-en: English:
Code: [Select]
$lang['image_md5'] = "Image MD5 hash";
$lang['image_md5_duplicate_self'] = "You have submitted this file before";
$lang['image_md5_duplicate_more'] = "This file has been previously submitted by %s";
$lang['image_md5_duplicate_simple'] = "This file has been previously submitted";
$lang['image_md5_duplicate_validation_self'] = "You have submitted this file before and awaiting validation.";
$lang['image_md5_duplicate_validation_more'] = "This file has been previously submitted by %s and awaiting validation.";
$lang['image_md5_duplicate_validation_simple'] = "This file has been previously submitted and awaiting validation.";

:flag-ru: Russian:
Code: [Select]
$lang['image_md5'] = "MD5 хэш файла";
$lang['image_md5_duplicate_self'] = "Вы уже раньше заливали этот файл";
$lang['image_md5_duplicate_more'] = "%s уже залили этот файл до вас";
$lang['image_md5_duplicate_simple'] = "Этот файл кто-то уже залил до вас";
$lang['image_md5_duplicate_validation_self'] = "Вы уже залили этот файл, и он ожидает подтверждения от администрации";
$lang['image_md5_duplicate_validation_more'] = "%s уже залили этот файл, и файл ожидает подтверждения от администрации";
$lang['image_md5_duplicate_validation_simple'] = "Кто-то уже залил этот файл, и файл ожидает подтверждения от администрации";


Step 4
Open includes/db_field_definitions.php
At the end, above closing ?> insert:
Code: [Select]
$additional_image_fields['image_md5'] = array($lang['image_md5'], "text", 0);




After installation in ACP (Admin Control Panel) in "Plugins" part of menu you should see new link "Image MD5 hash update".
When you click on it for the first time, the database installation process will start.
After new fields in the databse were added, you can again click on the "Image MD5 hash update" link and generate MD5 hash for all images in your gallery.

NOTE:
MD5 hash for remote images generates from the URL and not from the image content, so, if image was changed on the remote server, MD5 will not change.

P.S.
In case the download link doesnt work, I've attached the package, but I can not guarantee, that the attached package will be up-to-date in the future.

P.P.S.
This mod was created for 4images v1.7.3 but should work on v1.7 as well :)
Title: Re: [MOD] Check for duplicate images v1.0
Post by: impss on September 10, 2006, 10:11:50 AM
Thanks V@no ,


I have been needing something like this for awhile..

And it seems to be working good..

 :D
Title: Re: [MOD] Check for duplicate images v1.0
Post by: JensF on September 10, 2006, 07:17:22 PM
Hi,

is this Mod working when i say in ACP Upload Modus "save image with new name"????


Title: Re: [MOD] Check for duplicate images v1.0
Post by: V@no on September 10, 2006, 07:40:28 PM
yes, the filename is irrelevant for this mod.
Title: Re: [MOD] Check for duplicate images v1.0
Post by: JensF on September 10, 2006, 08:01:17 PM
OK, i will test it but i have a respect for this mod.

you say

Quote
If your images/files were resized, watermarked or altered in any way after they were uploaded, the MD5 hash will not be accurate, therefore will allow upload again the original files


My images are watermarked.....can anyone say me in german the problem???
Title: Re: [MOD] Check for duplicate images v1.0
Post by: antonio2005 on September 11, 2006, 01:07:55 AM
Great mod!!!!

Thanks a lot.

Simple but yet effective.

A fantastique piece of code.
Title: Re: [MOD] Check for duplicate images v1.0
Post by: antonio2005 on September 19, 2006, 12:23:02 PM
Hi Vano,

I´ve been using this mod since you posted it, and as i saud, it works great.

I´ld like to know if it is dificult to you to add another feature...  i explain:
If you have time... :lol:

When i instaled the mod, it generated the MD5 records for all files in the server... Perfect!
When i try to add an existant file, the mod doesnt allow..  Perfect!

What about the files i already had when i first run the script? is there any way to see if there is duplicate entries in the old files?
Is it dificult to add a menu like "Files Check" that will look at the whole database, and show only files with duplicate MD5 records, giving the possibility do delete one of them?

Thanks in advance,
António



Title: Re: [MOD] Check for duplicate images v1.0
Post by: V@no on September 19, 2006, 02:20:25 PM
Yes, I had thought about it, but since the MD5 hash is not indexed in the database, it creates too much load on the database (at least with the queries I've been testing it)...
anyways, untill I get my site back up this not gonna happend...
Title: Re: [MOD] Check for duplicate images v1.0
Post by: babe on October 05, 2006, 11:17:56 AM
Did anyone test the MD5 hash generation on a database with over 25k images? I wonder how long it would take and if it would succesfully complete with such a large collection.
Title: Re: [MOD] Check for duplicate images v1.0
Post by: impss on October 05, 2006, 03:14:23 PM
Did anyone test the MD5 hash generation on a database with over 25k images? I wonder how long it would take and if it would succesfully complete with such a large collection.

You tell it how many images to do at once, and it does it in steps.. and it continues by itself
I did 15k pictures at 100  pics at at time .. I didnt have any problems
Title: Re: [MOD] Check for duplicate images v1.0
Post by: babe on October 17, 2006, 06:27:40 PM
Did anyone test the MD5 hash generation on a database with over 25k images? I wonder how long it would take and if it would succesfully complete with such a large collection.

You tell it how many images to do at once, and it does it in steps.. and it continues by itself
I did 15k pictures at 100  pics at at time .. I didnt have any problems

Just perfect.

Hey, thanks for telling me that!
Title: Re: [MOD] Check for duplicate images v1.0
Post by: theolbap on November 30, 2006, 10:31:53 PM
Help!!

in form upload, photo is up. but appears

Warning: md5_file() [function.md5-file]: open_basedir restriction in effect. File(/tmp/phpzCUGaD) is not within the allowed path(s): (/www/docs/ahmira.com.ar/) in /www/docs/ahmira.com.ar/public_html/member.php on line 586

Warning: md5_file(/tmp/phpzCUGaD) [function.md5-file]: failed to open stream: Operation not permitted in /www/docs/ahmira.com.ar/public_html/member.php on line 586


i have v1.7.3, thx


Title: Re: [MOD] Check for duplicate images v1.0
Post by: theolbap on December 18, 2006, 07:45:41 PM
Help?
Title: Re: [MOD] Check for duplicate images v1.0
Post by: WeZ on January 11, 2007, 01:04:24 PM
Hi V@no,

I Trust you are well.

My site relies mostly on video within 4Images. My file sizes range from 1MB to over 200 or even 300MB files...

would it affect performance if this mod is applied to my site? when it generates a checksum, does it need to stream the entire file before it can generate it?

Kind Regards,
WeZ
Title: Re: [MOD] Check for duplicate images v1.0
Post by: WeZ on January 12, 2007, 09:44:02 AM
Hi V@no & The Rest...

How do i get this mod to integrate with "[Plugin] Batch Import" and "[MOD] multiupload". ?

Do i post this request on this topic or the other two?

Ciao
WeZ
Title: Re: [MOD] Check for duplicate images v1.0
Post by: WeZ on January 15, 2007, 02:49:36 PM
Can Anybody tell me how i get this mod to integrate with "[Plugin] Batch Import" and "[MOD] multiupload". ?

Ciao
WeZ
Title: Re: [MOD] Check for duplicate images v1.0
Post by: honda2000 on January 15, 2007, 07:52:29 PM
please! NO GARANTIE

multi look at this: http://www.4homepages.de/forum/index.php?topic=8517.120
batch-import look at this: http://www.4homepages.de/forum/index.php?topic=15429.0
Title: Re: [MOD] Check for duplicate images v1.0
Post by: jojomart on December 12, 2007, 05:17:55 AM
I just followed all the instructions and implemented the code, but I'm getting the following error message. Can someone help with this?  I'm using version 1.74

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, i.image_md5, c.cat_name, u.user_name FROM (4images_images i, 4images_categories c) LEFT JOIN 4images_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id NOT IN (0) ORDER BY i.image_date DESC LIMIT 5
Unknown column 'i.image_md5' in 'field list'

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/wannaber/public_html/wallpaper-downloads/includes/db_mysql.php on line 116


Thanks in advance,

Joanne
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Nicky on December 12, 2007, 11:13:18 AM
Joanne,

field image_md5 is missing in your image table
you didn't executed the plugin from Admin CP "PlugIns > Image MD5 hash upadate"  :mrgreen: (typo by V@no)
execute it.. then fields be added automaticly

then test it again
Title: Re: [MOD] Check for duplicate images v1.0
Post by: jojomart on December 12, 2007, 03:06:14 PM
Excellent!  Thanks so much - works great!

Joanne
Title: Re: [MOD] Check for duplicate images v1.0
Post by: TheUser on April 20, 2008, 10:56:13 PM
The link to the original package doesn't exist anymore.
Can anyone post another source?
Title: Re: [MOD] Check for duplicate images v1.0
Post by: mawenzi on April 21, 2008, 10:13:13 AM
... but the download link at the bottom of the first post works ... ;)
Title: Re: [MOD] Check for duplicate images v1.0
Post by: toolman1 on April 24, 2008, 11:25:05 PM
Hi.
I have few problems with this mod with using multiupload mod.
1. When sending for example 10 pictures, and two of them are the same, script don't tell me this and all images are uploaded.
2. Sometimes script don't detect the same picture in base.
3. Sometimes, two (ideal the same) pictures have two different md5 hash code. Why? I don't use any watermark mod.

Please help me, my gallery is very big (over 78800 gif's), and duplicate files are big problem.

Sorry for my bad english.
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Jan-Lukas on April 24, 2008, 11:42:14 PM
Help?

dein Avatar löst bei mir eine Virenmeldung aus
Tojanisches Pferd TR/Spy.Banker.vk.1
Title: Re: [MOD] Check for duplicate images v1.0
Post by: sanko86 on April 29, 2008, 10:01:45 AM
Joanne,

field image_md5 is missing in your image table
you didn't executed the plugin from Admin CP "PlugIns > Image MD5 hash upadate"  :mrgreen: (typo by V@no)
execute it.. then fields be added automaticly

then test it again

thanks ;)
Title: Re: [MOD] Check for duplicate images v1.0
Post by: uli480 on July 12, 2010, 01:07:38 PM
Where can i download this mod?
The downloadlink is broken
Title: Re: [MOD] Check for duplicate images v1.0
Post by: V@no on July 12, 2010, 02:12:06 PM
Welcome to 4images forum.

The file is attached to the first post
Title: Re: [MOD] Check for duplicate images v1.0
Post by: uli480 on July 14, 2010, 01:07:23 PM
thank you - it work's

is there also a way to add this by the check images and add images functions in the admincp?
Title: Re: [MOD] Check for duplicate images v1.0
Post by: V@no on July 14, 2010, 02:54:36 PM
Sorry, I don't understand the question.

Duplicate images check when using "Check new images" feature?
Title: Re: [MOD] Check for duplicate images v1.0
Post by: uli480 on July 14, 2010, 03:08:56 PM
i wanted to know if there is also a option to find duplciate picture when i add new pictures over the admincp or direct upload in a database folder
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Crazymodder on August 30, 2010, 09:46:31 PM
Hi very nice mod
Is it possible to make a plugin where you can detect double images. So that you run that plugin and generate the md5 hash of all the pictures and than a plugin which search inside the database for double entries in the md5 cell?
Than list double founded images and you can delete it...

Thanks
Crazymodder
Title: Re: [MOD] Check for duplicate images v1.0
Post by: V@no on August 31, 2010, 02:32:35 AM
sure

After installation in ACP (Admin Control Panel) in "Plugins" part of menu you should see new link "Image MD5 hash update".
When you click on it for the first time, the database installation process will start.
After new fields in the databse were added, you can again click on the "Image MD5 hash update" link and generate MD5 hash for all images in your gallery.
;)
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Crazymodder on August 31, 2010, 05:26:30 PM
Yes than all my images have an md5 hash. But I don't know if there are some pictures with the same md5 hash.
So I want to show alle pcitures with the same md5 hash so that i can delete the duplicates.
Title: Re: [MOD] Check for duplicate images v1.0
Post by: V@no on September 01, 2010, 05:46:15 AM
Now I see what you are saying.

currently there is no easy way to do so.

What you can do is run this query in phpmyadmin:
Code: (MySQL) [Select]
SELECT image_md5, COUNT(*) AS num
FROM 4images_images
GROUP BY image_md5
HAVING num>1
(assuming 4images_ is the table prefix set in your config.php)
It should give you a list of duplicate MD5 (if any)
Then having them, you can search for images using [MOD] Batch Copy/Move/Edit Images v4.15.1 (2010-08-14) (http://www.4homepages.de/forum/index.php?topic=6759.0) (make sure at MD5 search field select "default" in dropdown)
Title: Re: [MOD] Check for duplicate images v1.0
Post by: x23piracy on October 12, 2010, 03:32:47 AM
Now I see what you are saying.

currently there is no easy way to do so.

What you can do is run this query in phpmyadmin:
Code: (MySQL) [Select]
SELECT image_md5, COUNT(*) AS num
FROM 4images_images
GROUP BY image_md5
HAVING num>1
(assuming 4images_ is the table prefix set in your config.php)
It should give you a list of duplicate MD5 (if any)
Then having them, you can search for images using [MOD] Batch Copy/Move/Edit Images v4.15.1 (2010-08-14) (http://www.4homepages.de/forum/index.php?topic=6759.0) (make sure at MD5 search field select "default" in dropdown)

Hi,

i have 628 duplicate files in my galery, is there a method to search for that hashes with your mod at once?
Seems to be much work: pasting each hash into the search page and deleting them after that :)

Hope there is a clou?

Maybe something directly in database? but i don't know what rows have to be infected?
And how to submit the list of 628 hashes to the command that should delete that... uh i don't know


Greetz X23
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Guldstrand on June 16, 2011, 12:45:44 AM
Will this mod work on 1.7.10?  :?
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Eagle Eye on March 27, 2013, 09:27:56 AM
@Vano, Is it possible to modify this MOD to just simply check for duplicate filename only? Best variant would be to check for duplicate file name and extension while uploading

Thanks!
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Jan-Lukas on March 27, 2013, 05:15:58 PM
 :thumbup: das wäre klasse, schon beim hoch laden müsste eine Meldung kommen "Dateinamen vorhanden" und Unterscheidung groß und Kleinschrift.
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Rembrandt on March 27, 2013, 05:44:40 PM
Hi!
Ich verstehe nicht wozu ihr das braucht, wenn der "Dateiname" in dem selben Kategorie Ordner schon vorhanden ist, hängt 4images sowieso eine Zahl hinter den Namen drann.
Vorrausgesetzt ihr habt im ACP unter Allgemein/Einstellungen/Upload Einstellungen/Upload-Modus auf "Dateien mit neuem Namen speichern" gestellt.

mfg Andi
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Jan-Lukas on March 27, 2013, 10:42:24 PM
nicht immer Andy, Bild ist nicht gleich bild
OK, im Web wird das unterschieden, also nicht überschrieben, wenn ich aber die Bilder als Backup auf dem Compi lade, geht mir ein Bild verloren.
Dem Compi ist es egal ob ich Bild, bild BiLd oder bILd schreibe, es ist ein Name.
Und mir sind bei einem Serverwechsel schon einige verloren gegangen.
Mach einem User mal begreiflich das er die Bilder umbenennen soll  :cry:

Ich wäre generell dafür, das Bilder beim hoch laden als MD5 umgewandelt wird (habe ich im Portal)
z.B. so d99729bcd27fd077d056e9b39.jpg

LG Harald
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Rembrandt on March 28, 2013, 05:10:56 AM
Ok schon klar was du meinst, aber seit der V1.7.10 werden erstens die Dateinamen in Kleinbuchstaben umgewandelt und wenn sie gleichlautend sind, wie schon geschrieben ein Zahl hinten drann gehängt.
Somit gibt es keine Probleme mit einen Betriebssystem oder nach einen Serverwechsel.

mfg Andi
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Eagle Eye on March 28, 2013, 10:37:29 AM
@Vano, Is it possible to modify this MOD to just simply check for duplicate filename only? Best variant would be to check for duplicate file name and extension while uploading

Thanks!

This will be helpfull in sitivation where the file name does not change and a user uploads a same file with the same file name, instead of it being renamed and added, can this mod detect and warn that already a file with this name exists somewhere in database and need to proceed with the renaming or not!
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Jan-Lukas on March 28, 2013, 11:03:44 AM
Ok schon klar was du meinst, aber seit der V1.7.10 werden erstens die Dateinamen in Kleinbuchstaben umgewandelt und wenn sie gleichlautend sind, wie schon geschrieben ein Zahl hinten drann gehängt.
Somit gibt es keine Probleme mit einen Betriebssystem oder nach einen Serverwechsel.

mfg Andi

 :oops: stand das wo, war mir nicht bewusst, also mein Posting vergessen  :wink:

wünsche dir frohe Ostertage (allen anderen auch)

LG Harald
Title: Re: [MOD] Check for duplicate images v1.0
Post by: Rembrandt on March 28, 2013, 11:18:23 AM
... stand das wo,....
glaube nicht, das wurde in der 1.7.10 gemacht als die Probleme mit den Umlauten bestand.

Wünsche dir auch noch Frohe Ostern
Andi