Page 1 of 1

zip_open problem

Posted: Thu Sep 20, 2007 5:33 am
by mad_phpq
hi,

I have a problem unzipping a file. We have a zip file with an extension .lpz. When i try to unzip the folder inside, it unzips the structure, but the files all have a size of 0 bytes.

Code: Select all

$zip = zip_open ( $sZipFile );
			
			if ($zip) {
				while ($zip_entry = zip_read($zip)) {
					if (zip_entry_open($zip, $zip_entry, "rb")) {
						$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
			
						// Write the file
						$zipEntry = zip_entry_name ( $zip_entry );
						
						$zipEntry = str_replace ( '\\', '/', $zipEntry );
						
						if ( ( substr ( $zipEntry, 0, 1 ) == "\\" ) || ( substr ( $zipEntry, 0, 1 ) == "/" ) ){
							$zipEntry = substr ( $zipEntry, 1 );
						}
						
						//check that folder exists
						$iPos = strrpos ( $zipEntry, '/' );
						
						if ( $iPos > 0 ){
							$folder= substr ( $zipEntry, 0, $iPos );
							
							$aFolder = split ( '/', $folder );
							
							$sFolder = $iIndex . '/';
							
							foreach ( $aFolder as $fld ){
								$sFolder .= $fld . '/';

								if ( ! file_exists ( $sFolder ) ){
									mkdir ( $sFolder );
								}
								
							}

						}
						
						$path = $sUploadFolder . $zipEntry;

						//$fp = fopen(zip_entry_name($zip_entry), "wb");
						$fp = fopen($path, "wb");
						fputs($fp, $buf);
						fclose($fp);
		
						zip_entry_close($zip_entry);
					}
				}
				zip_close($zip);
			}		
			
		}