note 31769 modified in function.copy by vrana

From: Date: Tue, 17 Aug 2004 14:55:27 +0000
Subject: note 31769 modified in function.copy by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80035@lists.php.net to get a copy of this message
File ownership (on unix probably 'nobody') didnt have anything todo with the error of not being able to edit the file and eventually uploading it via a 'proper' userid and ftp-browser. My problem and my work around to michael at zend dot com snippet was lying in the file permission and fixed in one simple line: chmod("$newname", 0777); following the snippet again in total: <?php function my_copy($oldname, $newname) { if(is_file($oldname)){ $perms = fileperms($oldname); return copy($oldname, $newname) && chmod($newname, $perms); } else if(is_dir($oldname)){ my_dir_copy($oldname, $newname); } else{ die("Cannot copy file: $oldname (it's neither a file nor a directory)"); } } function my_dir_copy($oldname, $newname) { if(!is_dir($newname)){ mkdir($newname); chmod("$newname", 0777); } $dir = opendir($oldname); while($file = readdir($dir)){ if($file == "." || $file == ".."){ continue; } my_copy("$oldname/$file", "$newname/$file"); } closedir($dir); } ?> ------------- simply worked better for me. (host all-inkl.com) --was-- File ownership (on unix probably 'nobody') didnt have anything todo with the error of not being able to edit the file and eventually uploading it via a 'proper' userid and ftp-browser. My problem and my work around to michael at zend dot com snippet was lying in the file permission and fixed in one simple line: chmod("$newname", 0777); following the snippet again in total: function my_copy($oldname, $newname) { if(is_file($oldname)){ $perms = fileperms($oldname); return copy($oldname, $newname) && chmod($newname, $perms); } else if(is_dir($oldname)){ my_dir_copy($oldname, $newname); } else{ die("Cannot copy file: $oldname (it's neither a file nor a directory)"); } } function my_dir_copy($oldname, $newname) { if(!is_dir($newname)){ mkdir($newname); chmod("$newname", 0777); } $dir = opendir($oldname); while($file = readdir($dir)){ if($file == "." || $file == ".."){ continue; } my_copy("$oldname/$file", "$newname/$file"); } closedir($dir); } ------------- simply worked better for me. (host all-inkl.com) http://php.net/manual/en/function.copy.php

« previous php.notes (#80035) next »