Symptom:
- “Permission Denied” When trying to work with your site over FTP.
- You cannot modify directories inside the /files folder that were created by server program.
Solution:
- Tell Apache to give you back control of your files.
One side effect of having files created by server program (eg the image module), is that your user account might not have ownership of them any more. And you might not be able to delete the or move them around.
There is a workaround though. You can create a small PHP script containing the commands you want to carry out and upload it to the server. Once uploaded, you can run it from your web browser by entering the URL for it. The script will run as the user account the webserver runs as. Be sure to remove the script after you have used it though.
simple case:
Important: this code should only be used if you remember to delete it immediately after use. As above, its use may put your site into an insecure state.
<?php
file_fix_directory(dirname(__FILE__));
function file_fix_directory($dir, $nomask = array('.', '..')) {
if (is_dir($dir)) {
// Try to make each directory world writable.
if (@chmod($dir, 0777)) {
echo "<p>Made writable: " . $dir . "</p>";
}
}
if (is_dir($dir) && $handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (!in_array($file, $nomask) && $file[0] != '.') {
if (is_dir("$dir/$file")) {
// Recurse into subdirectories
file_fix_directory("$dir/$file", $nomask);
}
else {
$filename = "$dir/$file";
// Try to make each file world writable.
if (@chmod($filename, 0666)) {
echo "<p>Made writable: " . $filename . "</p>";
}
}
}
}
closedir($handle);
}
}
?>