Jump to content


Extract zip


  • You cannot reply to this topic
No replies to this topic

#1 Ultimatum

    Young Padawan

  • Members
  • Pip
  • 6 posts

Posted 03 July 2007 - 06:00 AM

I have a system, that you can upload a zip file and then it will extract automaticly to a folder you have choosen. But if the folder is empty it works perfectly, but when there is a photo in that folder the script extract the zip and duplicate the photo that was already in that folder. I wrote this class, can anybody see what I do wrong?

<?php
	class zip extends upload {
	
		public function __construct($file, $dir, $category = '') {
		
			if(!empty($category)) {
				
				$this->directory = $dir .'/'. categoryName($category);
				
			} else {
			
				$this->directory = $dir;
				
			}

			$zip = zip_open($_FILES[$file]['tmp_name']);
			while($zipEntry = zip_read($zip)) {
			
				$entry = zip_entry_open($zip, $zipEntry);
				$fileName = str_replace(' ', '_', zip_entry_name($zipEntry));
				$targetDir = $this->directory .'/'. substr($fileName, 0, strrpos($fileName ,'/'));
				$filesize = zip_entry_filesize($zipEntry);
				
				if (is_dir($targetDir) || mkdir($targetDir)) {
					if ($filesize > 0) {
						$contents = zip_entry_read($zipEntry, $filesize);
						file_put_contents($this->directory .'/'. $fileName, $contents);
					}
				}
			}
		}	
	}
?>

I think the problem lies by the file_put_contents

Edited by Ultimatum, 03 July 2007 - 06:01 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users