codecreative Posted September 27, 2013 Share Posted September 27, 2013 Hi I have a function in my script, that basically deletes all files in a folder excluding the supported file extensions once processing is complete. So it shouldn't delete files with the extension listed in the supported extension types within the array. Unfortunatly it wipes all the data files within the folder, primarily what I am targetting is pdf and doc file types. My code is as follows, I think once resolved this would be very useful for others to use in there projects possibly public function cleanBlmDirectory(){ if(empty($this->blmConfig['files_path'])){ return false; } $blmFiles = $this->__getBlmFiles(false); if(!empty($blmFiles)){ $supportedExts = array('blm', 'zip', 'jpg', 'jpeg', 'png', 'gif', 'bmp'); } else { $supportedExts = array('zip'); } $files = array(); $iterator = new DirectoryIterator($this->blmConfig['files_path']); while ($iterator->valid()) { if ($iterator->isDir() || $iterator->isDot() || $iterator->isLink()) { $iterator->next(); continue; } $fileinfo = $this->__getFileInfo($iterator); if (false === $fileinfo || in_array($fileinfo->extension, $supportedExts)) { $iterator->next(); continue; } @unlink($fileinfo->path); $iterator->next(); } } Quote Link to comment https://forums.phpfreaks.com/topic/282483-failing-file-removecleaner-script/ Share on other sites More sharing options...
jcbones Posted September 27, 2013 Share Posted September 27, 2013 What does $fileinfo->extension contain? Quote Link to comment https://forums.phpfreaks.com/topic/282483-failing-file-removecleaner-script/#findComment-1451454 Share on other sites More sharing options...
Solution codecreative Posted September 27, 2013 Author Solution Share Posted September 27, 2013 It's okay I fixed it! The script works it's just my own logic wasn't in tune with the logic of the if statement Quote Link to comment https://forums.phpfreaks.com/topic/282483-failing-file-removecleaner-script/#findComment-1451457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.