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!
I'm learning PHP. In my learning I came to chapter "Working with files and directories" . So here's the problem. I use openSUSE 11.0 (Linux) and in some way it seems like I don't have permission to access files . Here's the script, check it out :
<?php
// function definition
// remove all files in a directory
function removeDir($dir) {
if (file_exists($dir)) {
// create directory pointer
$dp = opendir($dir) or die ('ERROR: Cannot open directory');
// read directory contents
// delete files found
// call itself recursively if directories found
while ($file = readdir($dp)) {
if ($file != '.' && $file != '..') {
if (is_file("$dir/$file")) {
unlink("$dir/$file");
} else if (is_dir("$dir/$file")) {
removeDir("$dir/$file");
}
}
}
// close directory pointer
// remove now-empty directory
closedir($dp);
if (rmdir($dir)) {
return true;
} else {
return false;
}
}
}
// delete directory and all children
if (file_exists('psyco-1.6')) {
if (removeDir('psyco-1.6')) {
echo 'Directory successfully removed.';
} else {
echo 'ERROR: Directory could not be removed.';
}
} else {
echo 'ERROR: Directory does not exist.';
}
?>
... this is the example from the book. It is used to delete directory and all files in it. I get a message 'ERROR: Directory could not be removed.' ... and every time I try to edit any outer file with any script, with every try of editing I get an error message. So I guess it has something to do with permissions , or not? Files that I try to edit aren't locked and are easily edited in any other way . Please help.
Ensure the owner is the same (including group ownership). For example, a Linux user 'mike' cannot delete directories created by Linux user 'andy', unless of course Mike has superuser permissions.
People here volunteer their time and knowledge. They are not compelled to help. Please don't try to hurry people when they're doing you a favour.
If it really is important that you have a level of service faster than people will provide for free the solution is simple - pay. We have a "Job Hunt" folder here you can post in if you'd like to advertise for someone to come in an fix this fast. Remember to include plenty of information about the job.