Thursday, September 6, 2012

Recursive Directory Delete Function

9/06/2012

Recursive Directory Delete Function
<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/
define('PATH', '/www/public/images/');

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
");
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file
");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'all done.';

?>

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top