Question on PHP

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Hi,
Q)How can I do this? Please, give me idea and syntax

//files are from 2 different folders

if(file name of folder1 and folder2 not matches){
if(file size of folder1 and folder2 not matches
{
  we have to move unmatched files into a new folder
}
}
Posted by karanam-swathi7gmail-com
Asked on July 1, 2016 10:16 pm
0

<?php
define("MY_PATH", dirname(__FILE__));
// define("MY_PATH", "/var/www/html/project/images");

// set your custom paths
$dir[1] = MY_PATH."/dir1";
$dir[2] = MY_PATH."/dir2";
$dir[3] = $dir[1]."_processed"; // please note the folder "dir1_processed" must exist if you want to move files to it

// call the function and get the job done
echo compare_two_directory_images($dir);
?>
You can now use the below function to do the rest work.

<?php
function compare_two_directory_images($dir, $ext=".jpg", $move=true, $output=true){

$files = glob( $dir[1]."/*".$ext );

$count = 0;

if($output) echo "<pre>I found this duplicate files:<br />";

foreach ($files as $file) {

$file_name = basename($file);

// check if file exists in the second directory
if(file_exists($dir[2]."/".$file_name)){

if($output) echo "$file_name";

if($move) {
rename($file, $dir[3]."/".$file_name); // move the image to folder 3.
if($output) echo " <span style=’color:green’>moved</span> to ".basename($dir[3])."<br />";
} else {
unlink($file); // just delete the image
if($output) echo " <span style=’color:red’>deleted</span><br />";
}

$count++;
}

}

if($output) echo "</pre>";

return "Done processing and found <span style=’color:green’>$count</span> duplicated <span style=’color:red; font-weight:bold;’>$ext</span> files ";
} ?>

Posted by pHpSupport
Answered On July 1, 2016 10:33 pm