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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -