<?php require_once("../../classes/DBConnection.php"); $DB = new DBConnection();
$path_to_folder = trim($_POST['path_to_folder']); $n = 0; $p = 0;

echo "<span style='font-size:24px'>DUPLICATE REMOVAL IN {$path_to_folder}</span><br />";
$picturenames = scandir(trim($_POST['path_to_folder']));

foreach($picturenames as $picturename){
	$isDup = false;
	$n++;
	if($picturename!="." && $picturename!=".."){
		/*//try to rename to length of 4
		copy($path_to_folder.'/'.$picturename, $path_to_folder.'/'.substr($picturename, 0, 4).'.jpg');*/

		//Identify and remove the duplicates
		$k = strpos($picturename, '(');//echo "{$picturename} ... k = {$k}<br />";
		if($k > -1){
			$isDup = true;
		}

		if($isDup){
			$p++;
			unlink($path_to_folder.'/'.$picturename);
			echo "<br />Removed {$picturename}";
		}
	}
}


/*foreach($picturenames as $picturename){
	$isDup = true;
	$n++;
	if($picturename!="." && $picturename!=".."){
		//Identify and remove the duplicates
		$k = strpos($picturename, '.');
		if($k > -1){
			$ext = substr($picturename, $k+1);
			if($ext == 'jpg'){
				if(strlen($picturename) == 12) $isDup = false;
			}else if($ext == 'jpeg'){
				if(strlen($picturename) == 13) $isDup = false;
			}
		}

		if($isDup){
			$p++;
			unlink($path_to_folder.'/'.$picturename);
			echo "<br />Removed {$picturename}";
		}
	}
}*/
echo "<br />ENDED<hr />".($n-2)." file(s) processed."."<br />".($p)." duplicate(s) removed."."<br />".($n-2-$p)." file(s) left.";