BoltonWanderer
asked on
PHP CHOWN Script
Hi Guys
I wonder if someone can help me.
I need a script that iteratively changes any files/directories owned by Apache to the FTP username so that files can be manipulated.
I dont have root access but I understand you can do this using the CHOWN command.
We've found out that we can stop this in the future by setting up the domain differently but I have a live site that needs to be updated in this way.
Clearly I wouldnt leave the script on once completed but was hoping someone had already had this issue with Joomla/Magento installations.
Thanks in advance.
I wonder if someone can help me.
I need a script that iteratively changes any files/directories owned by Apache to the FTP username so that files can be manipulated.
I dont have root access but I understand you can do this using the CHOWN command.
We've found out that we can stop this in the future by setting up the domain differently but I have a live site that needs to be updated in this way.
Clearly I wouldnt leave the script on once completed but was hoping someone had already had this issue with Joomla/Magento installations.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Guys
Thanks for your comments thus far. Will the script iterate down through directories or will I have to run it for each directory?
Thanks
Thanks for your comments thus far. Will the script iterate down through directories or will I have to run it for each directory?
Thanks
This bit causes it to call a new copy of the function to drill down trough directories so a single run starting from the top level directory should handle it all the way down:
if (filetype ($thepath) == 'dir')
{
Change_Owner ($thepath, $uid);
}
Cd&
if (filetype ($thepath) == 'dir')
{
Change_Owner ($thepath, $uid);
}
Cd&
ASKER
Thats great, if I leave the path blank , i.e. '' then will it start from wherever file is located and work down through the tree? Like this ...
<?php
function Change_Owner($path, $uid)
{
$thedir = opendir ($path) ;
while(($file = readdir($thedir)) !== false)
{
if ($thefile != "." && $thefile != "..")
{
$thepath = $path . "/" . $file ;
if (filetype ($thepath) == 'dir')
{
Change_Owner ($thepath, $uid);
}
echo "Changing '".$thepath."' to be owned by '".$uid."'";
chown($thepath, $uid);
echo " .. done!";
echo "<br>";
}
}
}
Change_Owner("","newowner" );
?>
Thanks again!
<?php
function Change_Owner($path, $uid)
{
$thedir = opendir ($path) ;
while(($file = readdir($thedir)) !== false)
{
if ($thefile != "." && $thefile != "..")
{
$thepath = $path . "/" . $file ;
if (filetype ($thepath) == 'dir')
{
Change_Owner ($thepath, $uid);
}
echo "Changing '".$thepath."' to be owned by '".$uid."'";
chown($thepath, $uid);
echo " .. done!";
echo "<br>";
}
}
}
Change_Owner("","newowner"
?>
Thanks again!
ASKER
Thanks Guys, well sorted.
chmod ($my_file, 0777);