Forum Moderators: coopster

Message Too Old, No Replies

cp function / copy a directory and content,

cp function / copy a directory and content, plus give new directory differe

         

jbalestrieri

2:16 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



I am trying to get a directory “templates” to be copied to a different directory and assigned a new name based on form input… $newdir

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;
}
?>

jatar_k

10:49 pm on Jan 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



whatis it doing wrong? May help us narrow it down more.

jbalestrieri

11:18 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



It is not showing any errors or anything (of course I have been a little lazy about putting error checking in the script)

The problem is it is not creating the directory at all. I'm wondering if it is a directory path problem, or am I just doing this wrong.

Thanks for your help

BitBanger

11:40 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



Check the permissions on the destination folder. Chances are you don't have permission to write to that (or a previous) directory.