note 33713 added to function.copy

From: Date: Fri, 04 Jul 2003 18:05:35 +0000
Subject: note 33713 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-51525@lists.php.net to get a copy of this message
this function copyes a file or folder, it needs another function (ls_a): this works perfect. //////////////////////////////////////////////////////// /// cp function///////////////////////////////// //////////////////////////////////////////////////////// function cp($wf, $wto){ // it moves $wf to $wto mkdir($wto,0777); $arr=ls_a($wf); foreach ($arr as $fn){ if($fn){ $fl="$wf/$fn"; $flto="$wto/$fn"; if(is_dir($fl)) cp($fl,$flto); else copy($fl,$flto); } } } /////////////////////////////////////////////////// /// ls_a function//////////////////////// // This function lists a directory. // ANd is needed for the cp function. function ls_a($wh){ if ($handle = opendir($wh)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." ) { if(!$files) $files="$file"; else $files="$file\n$files"; } } closedir($handle); } $arr=explode("\n",$files); return $arr; } ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33713 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33713&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33713&report=yes

« previous php.notes (#51525) next »