Is there a way to check duplicate images with different names using php? [closed] Is there a way to check duplicate images with different names using php? [closed] php php

Is there a way to check duplicate images with different names using php? [closed]


Yes, you could iterate over all files and use the hash_file function to compare them:http://php.net/manual/en/function.hash-file.php


I suppose a somewhat simple solution would be to do a checksum on the images using md5().

Open a directory, loop through the files generating md5s, compare md5s, delete duplicates.

EDIT: Here's a script using hash_file()

<?php$dir = "/full/path/to/images";$checksums = array();if ($h = opendir($dir)) {    while (($file = readdir($h)) !== false) {        // skip directories        if(is_dir($_="{$dir}/{$file}")) continue;        $hash = hash_file('md5', $_);        // delete duplicate        if (in_array($hash, $checksums)) {            unlink($_);        }        // add hash to list        else {            $checksums[] = $hash;        }    }    closedir($h);}


You can compare and check it by sha1_file hash of a file

It returns 40 character hex number