mindspins Posted October 4, 2011 Share Posted October 4, 2011 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/248392-renaming-folders-only-works-with-chmodd-777/ Share on other sites More sharing options...
requinix Posted October 4, 2011 Share Posted October 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248392-renaming-folders-only-works-with-chmodd-777/#findComment-1275676 Share on other sites More sharing options...
mindspins Posted October 4, 2011 Author Share Posted October 4, 2011 I know what you're trying to achieve, but the user is the owner of the folders in use and is triggering the php. That's why I don't understand it?! Quote Link to comment https://forums.phpfreaks.com/topic/248392-renaming-folders-only-works-with-chmodd-777/#findComment-1275749 Share on other sites More sharing options...
requinix Posted October 4, 2011 Share Posted October 4, 2011 Are you sure your PHP scripts are actually running as your user? Normally they are not - it takes a special setup for that to happen. Quote Link to comment https://forums.phpfreaks.com/topic/248392-renaming-folders-only-works-with-chmodd-777/#findComment-1275752 Share on other sites More sharing options...
mindspins Posted October 4, 2011 Author Share Posted October 4, 2011 Well... you've got me doubting here... I might just need to check your solution after I get some sleep... I'll let you know after a good night rest! Quote Link to comment https://forums.phpfreaks.com/topic/248392-renaming-folders-only-works-with-chmodd-777/#findComment-1275790 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.