Link to home
Start Free TrialLog in
Avatar of BoltonWanderer
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.
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think CD& has a good answer for you.  You might also be able to do something like this:

chmod ($my_file, 0777);
Avatar of BoltonWanderer
BoltonWanderer

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
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&
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!
Thanks Guys, well sorted.