Forum Moderators: coopster
I have been able to do it in the past with ftp functions, but the server I’m working on now will not have ftp turned on when it goes production.
Here is the script I’m working with, but for some reason I can not get it to work. Any suggestions? I’m stumped…
<?php
@extract($_POST);
$newdir = $_GET['$newdir'];
$writenewdir = "/home/web/content/$newdir";
$template = "/home/sites/site75/web/stage/scripts/template";
function cp($template, $writenewdir){ // it moves $template to $writenewdir
if (!file_exists($writenewdir)){
mkdir($writenewdir,0777);
}
$arr=ls_a($template);
foreach ($arr as $fn){
if($fn){
$fl="$template/$fn";
$flto="$writenewdir/$fn";
if(is_dir($fl)) cp($fl,$flto);
else copy($fl,$flto);
}
}
}
// This function lists a directory for cp funcion.
function ls_a($template){
if ($handle = opendir($template)) {
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;
}
?>