Permission denied error when using rename()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
funkyapache
Forum Newbie
Posts: 11
Joined: Tue Mar 24, 2009 11:19 am

Permission denied error when using rename()

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Permission denied error when using rename()

Post by requinix »

Everybody ("other") must have write access to the pix directory. Did you check that?
funkyapache
Forum Newbie
Posts: 11
Joined: Tue Mar 24, 2009 11:19 am

Re: Permission denied error when using rename()

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Permission denied error when using rename()

Post 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?
funkyapache
Forum Newbie
Posts: 11
Joined: Tue Mar 24, 2009 11:19 am

Re: Permission denied error when using rename()

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Permission denied error when using rename()

Post 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?
Post Reply