codeigniter - How to delete a file which have such type of extensions in php? -
what i'm trying is, delete files includes such type of extensions.
let's folder images/
contains following files,
a.jpg b.jpeg c.php d.php2 c.png
so want delete c.php,d.php2
. there way in single step or ideas ?
note: in case, not know exact name of file or extension.
thank in advance.
to delete specific extension files sub directories, can use following function. example:
<?php function delete_recursively_($path,$match){ static $deleted = 0, $dsize = 0; $dirs = glob($path."*"); $files = glob($path.$match); foreach($files $file){ if(is_file($file)){ $deleted_size += filesize($file); unlink($file); $deleted++; } } foreach($dirs $dir){ if(is_dir($dir)){ $dir = basename($dir) . "/"; delete_recursively_($path.$dir,$match); } } return "$deleted files deleted total size of $deleted_size bytes"; } ?>
e.g. remove text files can use follows:
<?php echo delete_recursively_('/home/username/directory/', '.txt'); ?>
Comments
Post a Comment