Jump to content

Failing file remove/cleaner script


codecreative

Recommended Posts

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();
		}
	}
	
Link to comment
https://forums.phpfreaks.com/topic/282483-failing-file-removecleaner-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.