Removing directory and its contents in php -
i trying remove folders , files , sub folders using php.
this how tried it.
$dir = "../../images/$category_id/$delid"; $it = new recursivedirectoryiterator($dir, recursivedirectoryiterator::skip_dots); $files = new recursiveiteratoriterator($it, recursiveiteratoriterator::child_first); foreach($files $file) { if ($file->isdir()){ rmdir($file->getrealpath()); } else { unlink($file->getrealpath()); } } rmdir($dir);
this working on php 5.5+, doesn't work in php 5.2.17.
can tell me how work on 5.2 also. thank you.
use below code:-
function rrmdir($dir) { foreach(glob($dir . '/*') $file) { if(is_dir($file)) rrmdir($file); else unlink($file); } rmdir($dir); }
you can below statement:-
system('/bin/rm -rf ' . escapeshellarg($dir));
hope :)
Comments
Post a Comment