note 27867 added to function.copy
| From: | php at snr-graphics dot com | Date: | Sat, 21 Dec 2002 17:08:19 +0000 |
| Subject: | note 27867 added to function.copy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41185@lists.php.net to get a copy of this message | ||
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 ...
$match = ereg_replace("/","\\/",$from);
if (!@preg_match("/^".$match."/",$to)) {
//call the copy function
}
else {
//output error response as source and destination are same
}
--
http://www.php.net/manual/en/function.copy.php
http://master.php.net/manage/user-notes.php?action=edit+27867
http://master.php.net/manage/user-notes.php?action=delete+27867
http://master.php.net/manage/user-notes.php?action=reject+27867