Forum Moderators: coopster
I need to be able to do a recursive copy of a directory on a staging server (virtual) to a the production server (another virtual on the same machine.) I've been tring the examples at [php.net...] after much tweaking, I still can not get this to work. I get no errors anywhere and when I check the paths they are correct. The permissions are correct as well.
My Question: Is this even possible?
Here is the code I've been trying...
@extract($_POST);
$basedir = "/var/www/html/internal/contents/projects/";
$tobase ="/var/www/html/live/contents/projects/";
$wf = "$basedir$type";
$wto = "$tobase$type";
echo "$wf<br>";
echo "$wto<br>";
function cp($wf, $wto){ // it moves $wf to $wto
if (!file_exists($wto)){//the improvement
mkdir($wto,0777) or die ("Could not chmod destination (this is line 21");
}
$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) or die ("could not copy directory ");
}
}
}
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);
for($i=0;$i<count($arr);$i++){
echo "<br>$arr[$i]";
}
return $arr;
}
?>
If this is a public server please take note that there is a security advisory for rsync versions prior to 2.5.7.
** If you're using a version prior to 2.5.7, please see the security advisory below! **
h**p://rsync.samba.org/#security