note 77240 deleted from function.readdir by danbrown

From: Date: Thu, 25 Feb 2010 20:31:46 +0000
Subject: note 77240 deleted from function.readdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166369@lists.php.net to get a copy of this message
Note Submitter: minisprinter (at) naver (dot) com ---- The following code is a bit nasty, it can be used to remove all files generated by apache. You're not a root user on a system, but you sometimes need to remove all files generated by apache in a certain directory. You may use this after replacing 'bbs' at the bottom with 'directory' you want. It tries to remove all files in a directory, but it can't unless it has an ownership. it doesn't check the ownership or permission. <?php function remove($dirname = '.') { if (is_dir($dirname)) { echo "$dirname is a directory.<br />"; if ($handle = @opendir($dirname)) { while (($file = readdir($handle)) !== false) { if ($file != "." && $file != "..") { echo "$file<br />"; $fullpath = $dirname . '/' . $file; if (is_dir($fullpath)) { remove($fullpath); @rmdir($fullpath); } else { @unlink($fullpath); } } } closedir($handle); } } } remove('bbs'); ?>

« previous php.notes (#166369) next »