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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -