Archive for January 27th, 2006

Let’s assume that you have a script that creates folders and files with specific php functions.
On Linux-based servers, these files and folders belongs to “apache” user, and not to you. Of course, you can create them with 777 permissions, but default is 755, which means no write permissions to other users and groups than “apache”.
Can you delete these files and folders through FTP ? No way.
The only way to delete them is like you create (through php functions, under the “apache” user):
unlink (file) deletes a file
rmdir (folder) deleted a folder
You can use them independently or, if you want to recursive delete a folder, its subfolders and files you can use this function (i found it php manual unlink page):

function SureRemoveDir($dir) {
   if(!$dh = @opendir($dir)) return;
   while (($obj = readdir($dh))) {
     if($obj==‘.’ || $obj==‘..’) continue;
     if (!@unlink($dir.‘/’.$obj)) {
     } else {
   if (@rmdir($dir)) $dir_deleted++;

and you can simply call it as:

<? SureRemoveDir ("Test"); ?>

Another techniques can also solve this situation, such as:
– if you have SSH access, you can user sudo chown command to take control and then delete then normally
– you can ask for help to an administrator (he will also use the sudo chown)
– use suExec, if it is installed on the machine


Comments 4 Comments »