...

View Full Version : directory copy with chown



ziggy1621
07-05-2007, 11:27 PM
i'm using the script below to make a directory, then copy the contents of another directory into the new one. Problem is... its not setting the owner, so I can't delete/modify the files. Can someone point out how I can chown the files as they are copied?

Thanks in advance.



<?php
$firstName=$_REQUEST['firstName'];
$lastName=$_REQUEST['lastName'];

mkdir('../../'.$firstName.$lastName, 0777);

function copydirr($fromDir,$toDir,$chmod=0757,$verbose=false)
{
//* Check for some errors
$errors=array();
$messages=array();
if (!is_writable($toDir))
$errors[]='target '.$toDir.' is not writable';
if (!is_dir($toDir))
$errors[]='target '.$toDir.' is not a directory';
if (!is_dir($fromDir))
$errors[]='source '.$fromDir.' is not a directory';
if (!empty($errors))
{
if ($verbose)
foreach($errors as $err)
echo '<strong>Error</strong>: '.$err.'<br />';
return false;
}
//*/
$exceptions=array('.','..');
//* Processing
$handle=opendir($fromDir);
while (false!==($item=readdir($handle)))
if (!in_array($item,$exceptions))
{
//* cleanup for trailing slashes in directories destinations
$from=str_replace('//','/',$fromDir.'/'.$item);
$to=str_replace('//','/',$toDir.'/'.$item);
//*/
if (is_file($from))
{
if (@copy($from,$to))
{
chmod($to,$chmod);
touch($to,filemtime($from)); // to track last modified time
$messages[]='File copied from '.$from.' to '.$to;
}
else
$errors[]='cannot copy file from '.$from.' to '.$to;
}
if (is_dir($from))
{
if (@mkdir($to))
{
chmod($to,$chmod);
$messages[]='';
}
else
$errors[]='cannot create directory '.$to;
copydirr($from,$to,$chmod,$verbose);
}
}
closedir($handle);
//*/
//* Output
if ($verbose)
{
foreach($errors as $err)
echo '<strong>Error</strong>: '.$err.'<br />';
foreach($messages as $msg)
echo $msg.'<br />';
}
//*/
return true;
}

copydirr('memberTemplate','../../'.$firstName.$lastName,0777,true);
?>

mr_ego
07-06-2007, 12:54 AM
http://au3.php.net/chmod

of course you'd want to chmod to 0777

ziggy1621
07-06-2007, 01:08 PM
http://au3.php.net/chmod

of course you'd want to chmod to 0777

Thanks, but as you can see from the above script, they are being CHMOD'd to 777. If you look at what I posted, they are being 'owned' by root and not by me (shared hosting). Please read entirely before posting as most people only read them if there are 0 replies.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum