Jump to content


- - - - -

Nobody file removal script


  • You cannot reply to this topic
No replies to this topic

#1 DS-Dennis

    System Administrator

  • Administrators
  • 518 posts
  • Gender:Male
  • Location:Netherlands

Posted Aug. 29, 2008 - 01:54 am

If you use a script that creates files owned by nobody you will be unable to delete them without using this script.

Create a php file named nobodydelete.php and insert the following php code into it:
<?php

define('PATH', './directoryToDelete/');

function destroy($dir) {
    $mydir = opendir($dir);
    while(false !== ($file = readdir($mydir))) {
        if($file != "." && $file != "..") {
            chmod($dir.$file, 0777);
            if(is_dir($dir.$file)) {
                chdir('.');
                destroy($dir.$file.'/');
                rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
            }
            else
                unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
        }
    }
    closedir($mydir);
}
destroy(PATH);
echo 'Nobody files deleted.'; 

?>
Modify the ./directoryToDelete/ in the above code to the directory you need to delete.
Example: /home/username/public_html/screenshots would be:

define('PATH', '/home/username/public_html/screenshots');
Then run the script from your domain.
Example: yourdomain.com/nobodydelete.php

It will show Nobody files deleted after you access the file.

When you are done using the script make sure to delete it.







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users