Jump to content

renaming folders only works with chmodd 777


mindspins

Recommended Posts

I'm using the following code in a WordPress functions file to rename a folder in the uploads folder according to the date, but this only works if the chmodd settings of both folders are 777. How can I change this code so I can use at least chmodd 755 to keep my website save.

 

date_default_timezone_set('Europe/Amsterdam'); // set timezone
$foldername = '';
$source = 'uploads';
$allfolders = getDirectory($source); // get folders
$folder = $source.'/'.$allfolders[0]; // get first folder
$month = (int)date('n');
$day = (int)date('j');
$f = 50-$day; $s = 100-$month;
$newfolder = $source.'/'.(string)$f.(string)$s;
if($folder != '' && $folder != $newfolder){
rename($folder, $newfolder);
$foldername = $newfolder."/";
}else if($folder == $newfolder){
$foldername = $newfolder."/";
}
else{ $foldername = 'error';
}

Link to comment
Share on other sites

Steps for you:

1. Move everything in the uploads folder someplace else temporarily

2. Delete the uploads folder

3. chmod 077 the folder which contained the uploads folder

 

In a PHP script:

4. Recreate the uploads folder. Keep the default 0755 permissions

5. Move everything back

 

You:

6. chmod 0755 the parent folder

 

This way PHP is the owner of the uploads folder and can do whatever it wants inside of it. Alternatively, if you have root access, you just chown the folder to whatever user PHP/Apache runs as.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.