Reputation: 2647
I am trying to write an install script for a system I have been working on. The script copies some default files from one location to another, and creates various folders for them. I have this bit working a treat, but the only problem is that when I login via FTP, I can't edit, or delete the files that PHP has moved for me.
If I login via terminal I can happily "sudo chmod -R 777 [dir]" and the problem goes away, so the question is:
What am I missing on the PHP end?
my permissions function is as follows:
function set_permissions($file)
{
if (file_exists($file)):
chmod($file,0777);
endif;
}
I understand it's not 100% ideal to set the permissions to 777, but I am simply trying to achieve the result of being able to edit the files via FTP, after PHP has moved them for me.
Hope I've been clear enough. This is puzzling me now so any help is appreciated :)
Tom
edit: The whole process is as follows:
mkdir($root_dir, 0777);
mkdir($images_dir, 0777);
if (!copy($orig_logo, $new_logo))
{
echo "failed to copy $orig_logo...";
}
// see function above for details on set_permissions...
$this->set_permissions($new_logo);
}
(All the paths are correct too)
edit: The file before I login via terminal has the following permissions:
-rwxrwxrwx 1 www-data www-data 2739 2009-08-26 01:45 base.css
The file after I login and change it has:
-rwxrwxrwx 1 www-data www-data 2739 2009-08-26 01:45 base.css
The system is a content management system that allows you to edit and delete files through the admin area, and strangely enough, this works well. It seems like the files are somehow locked out from anybody else other than Apache... but the file info suggests otherwise. It's odd...
Upvotes: 1
Views: 1741
Reputation: 91028
If you can chmod -R 777
via terminal to fix the problem, then what were the permissions set to by PHP before you ran chmod
??? Obviously not 777. My guess is that your PHP code is not actually changing the permissions.
Lookat at your code, your permission-changing function could be failing silently if the file doesn't exist - e.g., you're giving it invalid file names (wrong folder? wrong relative path?) but you can't tell because your set_permissions()
function is too scared of warning you. You should rewrite it as follows:
function set_permissions($file)
{
if (!file_exists($file))
throw new Exception(__FUNCTION__ . "() file doesn't exist! '$file'");
chmod($file,0777);
error_log("chmod 777 $file"); // debug
}
This allows you to see what's happening, and you'll certainly notice if you haven't got your file names correct.
Upvotes: 1