Deleting specific file types recursively


I’m working on a function where a user can upload a zip file to the server and unzip it. That’s all going well, however I need to be able to scan through the directories and sub-directories for file types I don’t allow (such as .exe) and delete them. This would take place after the zip file has been extracted.

I’m working with unlink and glob, but I haven’t yet found the magic combination. Any suggestions from those with more experience or who have done such a thing in the past would be greatly appreciated!

Thanks in advance.

recursion can’t be done with glob.

try to use the function i provided:

<?php $subdirs=subdirs('path2unzipedfiles'); foreach($subdirs as $subdir) { copy('viewer.php',$subdir.'viewer.php'); $files=glob($subdir.'*.exe'); foreach($files as $file) { unlink($file); } } ?>



Thanks…that works when tested. What would be the right syntax for multiple file types? For instance if I wanted to delete both .exe and .ini files.

Thanks in advance.


Works perfectly! Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service