Sie befinden sich hier im Forenarchiv von phpforum.de wenn Sie direkt ins Forum möchten, klicken Sie bitte hier. Zur Startseite kommen Sie hier.

Verzeichnis kopieren

Hallo,<br><br>ich habe einen Code gefunden, mit dem man komplette Verzeichnisstrukturen, mit samt Dateien, kopieren kann. Leider Funktioniert es nicht. Kann jemand einen Fehler erkennen.<br><br>&lt;?PHP<br>$from_path = &quot;test&quot;;<br>$to_path = &quot;test1&quot;;<br>function rec_copy ($from_path, $to_path) { <br>mkdir($to_path, 0777); <br>$this_path = getcwd(); <br>if (is_dir($from_path)) { <br>chdir($from_path); <br>$handle=opendir('.'); <br>while (($file = readdir($handle))!==false) { <br>if (($file != &quot;.&quot;) &amp;&amp; ($file != &quot;..&quot;)) { <br>if (is_dir($file)) { <br><br>rec_copy ($from_path.$file.&quot;/&quot;, $to_path.$file.&quot;/&quot;); <br>chdir($from_path); <br>} <br>if (is_file($file)){ <br>copy($from_path.$file, $to_path.$file); <br>} <br>} <br>} <br>closedir($handle); <br>} <br>}<br>?&gt;<br><br>F&uuml;r einen anderen Vorschlag bin ich auch offen. <br>Besten Dank<br><br>Andi

Hier gehts zum Orginal Eintrag "Verzeichnis kopieren" im Forum

Antworten

dieses problem hatte ich auch schon.<br>versuchs mit exec(&quot;cp -R sourcedir destdir&quot;);<br>es lebe unix. du wirst merken wie viel schneller dieses kopieren vonstatten geht.<br><br>gruss


2.

hi, hier der korrekte code...

function rec_copy ($from_path, $to_path)
{
mkdir($to_path,0777);
$this_path = getcwd();

if (is_dir($from_path))
{
chdir($from_path);
$handle=opendir('.');

while (($file = readdir($handle))!==false)
{
if (($file != ".") && ($file != ".."))
{
if (is_dir($file))
{
rec_copy ($from_path."/".$file."/", $to_path.$file."/");
echo $from_path.$file."/<br>";
echo $to_path.$file."/<br>";
chdir($from_path);
}
if (is_file($file))
{
copy($from_path."/".$file, $to_path.$file);
}
}
}

closedir($handle);
}
}


Hier gehts zum Orginal Eintrag "Verzeichnis kopieren" im Forum
 
phpforum.de | Impressum | Handy Bundles