Moving repeated files from one folder to another I want to scan my whatsapp images folder and move all the repeated images to folder named recycle bin to delete them later:

&lt;?php

$dir    = 'C:\wamp\www\whatsapp';
$files = scandir($dir);

$x = 0;

foreach($files as $f1)
{

    $crc1 = strtoupper(dechex(crc32(file_get_contents("whatsapp/".$f1))));

    unset($files[$x]);

    $j = 0;

    foreach($files as $f2)
    {

        $crc2 = strtoupper(dechex(crc32(file_get_contents("whatsapp/".$f2))));

        if($crc1 == $crc2){

            rename("whatsapp/".$f2, "recycle bin/".$f2);

            unset($files[$j]);
        }

        $j++;
    }

    $x++;
}

exit('Done');


Does this code seems to be trusted to move only the repeated images without any mistakes?
Maybe you try with this pseudocode:


get files list from directory
declare array for crc
for each file in directory
check if the mime content type is correct
get crc for file 
check if this crc is in array for crc
if is in array move it
else push crc into array


Thanks Pimgd. You are right. I should write it on the beginning. First of all there is only one loop, so if you have a lot of files, it will be faster. Second, it checks content file, so you will not touch not image files. Third, the code will be more clear.