Page 1 of 1

Permission denied error when using rename()

Posted: Wed Mar 25, 2009 4:08 pm
by funkyapache
HI

I'm trying to rename a load of directorys in one of my folders

Code: Select all

<?php
  $dir    = '/opt/lampp/htdocs/websites/pix';
  $files1 = scandir($dir);
?>
<?php
    $dir    = '/opt/lampp/htdocs/websites/pix';
    $files1 = scandir($dir);
    foreach ($files1 as $fileobject){
      $newfileobject = str_replace(" ", "_" ,strtolower($fileobject));
      $newfile = $dir . "/" . $newfileobject;
      $oldfile = $dir . "/" . $fileobject;
      if (is_dir($oldfile) && ($fileobject != "." && $fileobject != "..")){
        rename($oldfile,$newfile);
        echo "$fileobject : Changed to $newfile<br>";
      }
    }
?>
 
I get the following error : Permission denied on line 13. I checked the permissions under the properties folder and made everyobdy have read and write access but this did not work. Of course I don't want any user other than myself to be able to modify my files/folders but they must be able to view the pictures which are placed in these folders.

Re: Permission denied error when using rename()

Posted: Wed Mar 25, 2009 4:12 pm
by requinix
Everybody ("other") must have write access to the pix directory. Did you check that?

Re: Permission denied error when using rename()

Posted: Wed Mar 25, 2009 4:24 pm
by funkyapache
I could swear that I had check that but once I change my Pix folder it worked. Thanks a million. How can I restrict it so that only I can modify/delete files/folders using that script.

Re: Permission denied error when using rename()

Posted: Wed Mar 25, 2009 4:57 pm
by requinix
You can't, really. Unix doesn't give fine-grained permissions controls like Windows does: if Apache/PHP is allowed to do something then everybody else can too.

But you can make Apache own the pix folder.
Is this a dedicated server? Do you have root access?

Re: Permission denied error when using rename()

Posted: Wed Mar 25, 2009 5:03 pm
by funkyapache
I'm running ubuntu 8.10 with lampp installed. I do have root access. I am creating a personal website that has a photo gallery and I just want to ensure that security is setup correctly.

Re: Permission denied error when using rename()

Posted: Wed Mar 25, 2009 5:30 pm
by requinix
If it's just your server then you don't have much to worry about. Only files on the server are yours or the ones you allow. If there isn't any code to do anything to those files besides the one script then they're safe.

Anything in particular you're worried about?