Ben başlangıçta ben iki klasör yapısının farkını alıyorum ve sonra koymak dışarı diğer klasörüne kopyalanması gerekir ki, şu WINDOWS işletim sistemi kodu ve PHP komut dosyası kullanıyorum. aşağıda kodu ..
$source = '/var/www/html/copy1';
$mirror = '/var/www/html/copy2';
function scan_dir_recursive($dir, $rel = null) {
$all_paths = array();
$new_paths = scandir($dir);
foreach ($new_paths as $path) {
if ($path == '.' || $path == '..') {
continue;
}
if ($rel === null) {
$path_with_rel = $path;
} else {
$path_with_rel = $rel . DIRECTORY_SEPARATOR . $path;
}
$full_path = $dir . DIRECTORY_SEPARATOR . $path;
$all_paths[] = $path_with_rel;
if (is_dir($full_path)) {
$all_paths = array_merge(
$all_paths, scan_dir_recursive($full_path, $path_with_rel)
);
}
}
return $all_paths;
}
$diff_paths = array_diff(
scan_dir_recursive($mirror),
scan_dir_recursive($source)
);
/*$diff_path = array_diff($mirror,$original);*/
echo "<pre>Difference ";print_r($diff_paths);
Difference of Folders Array
(
[4] => New Folder (2)
[5] => New Folder (2)/New Folder
[6] => New Folder (2)/New Folder/New Folder
[7] => New Folder (2)/New Folder/New Folder/New Text Document (2).txt
[8] => New Folder (2)/New Folder/New Folder/New Text Document.txt
)
foreach($diff_paths as $path)
{
echo $source1 = "var/www/html/copy2/".$path;
echo "<br>";
$des = "var/www/html/copy1/".$path;
copy_recursive_dirs($source1, $des);
}
function copy_recursive_dirs($dirsource, $dirdest)
{
$dir_handle=opendir($dirsource);
mkdir($dirdest,0777);
while(false!==($file=readdir($dir_handle)))
{/*echo "<pre>";
print_r($file);*/
if($file!="." && $file!="..")
{
if(is_dir($dirsource.DIRECTORY_SEPARATOR.$file))
{
//Copy the file at the same level in the destination folder
copy_recursive_dirs($dirsource.DIRECTORY_SEPARATOR.$file, $dirdest.DIRECTORY_SEPARATOR.$file);
}
else{
//Copy the dir at the same lavel in the destination folder
copy ($dirsource.DIRECTORY_SEPARATOR.$file, $dirdest.DIRECTORY_SEPARATOR.$file);
}
}
}
closedir($dir_handle);
return true;
}
Ben fark çıktı almak çalıştırabiliriz ama kod başı olarak ikinci bir klasör üzerindeki diğer kopyasını alamadım zaman ... Pls giderilmesi bana yardım ...
UPDATE I just want to copy the difference to other folder, if theere is any other way pls help me....
UPDATE: I am getting these errors,
( ! ) Warning: opendir(var/www/html/copy2/New Folder (2)) [function.opendir]: failed to open dir: No such file or directory in /var/www/html/pranav_test/syncss.php on line 96
( ! ) Warning: mkdir() [function.mkdir]: No such file or directory in /var/www/html/pranav_test/syncss.php on line 99
( ! ) Warning: readdir(): supplied argument is not a valid Directory resource in /var/www/html/pranav_test/syncss.php on line 104
( ! ) Warning: closedir(): supplied argument is not a valid Directory resource in /var/www/html/pranav_test/syncss.php on line 122