Jump to content

Failing file remove/cleaner script


Go to solution Solved by 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.