note 27867 deleted from function.copy by aidan

From: Date: Mon, 30 Aug 2004 07:27:53 +0000
Subject: note 27867 deleted from function.copy by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75647@lists.php.net to get a copy of this message
Note Submitter: php at snr-graphics dot com ---- As already noted, the rec_copy function only work(ed)(s) on the "first" level and then dies .. naturally the problem was/is rather simple.. as it failed to account for the trailing slash(es) of the directories.. Another issue to consider, when working with a recursive function, is the possiblity of copying to a destination that lies within the source path.. i.e. from=./tmp to=./tmp/test given the manner in which rec_copy operates, it writes the destination directory, then reads from the source.. you wind up with a tree where /test is duplicated endlessly. i.e ./tmp/test/test/test/test/test/................... perhaps obvious to the veteran programmer, but not quite so obvious to the newcomer. the simplest solution - looking at the sample - would be to prevent the copy if the destination lies within the source.. one way might be to ... <?php $match = ereg_replace("/","\\/",$from); if (!@preg_match("/^".$match."/",$to)) { //call the copy function } else { //output error response as source and destination are same } ?>

« previous php.notes (#75647) next »