| 
 | 
  André Silva - 2007-07-12 14:11:35  
Hello, 
When I tested the exemple2.php the content of the files had not been shown using {$file['data']}, why? There are any dependency to run this class? 
Also I had tested this class to unpack images and to transfer them to a directory in my server, but an error occurred informing that the files had not been found. Could you explain me how I make to unpack the compressed files in another place in my server? It's very important for me now. 
Thank you. 
  
  Joshua Townsend - 2007-07-17 04:52:56 -  In reply to message 1 from André Silva 
Here is the contents of example2.php: 
<?php 
require "zip.class.php"; // Get the zipfile class 
$zipfile = new zipfile; // Create an object 
$zipfile->read_zip("myzip.zip"); // Read the zip file 
 
// Now, $zipfile->files is an array containing information about the files 
// Here is an example of it's use 
 
foreach($zipfile->files as $filea) 
{ 
    echo "The contents of {$filea['name']}:\n{$file['data']}\n\n"; 
} 
?> 
 
$zipfile->files contains an array in which each sub-array contains information about the files that have been unzipped.  To unzip every file in a zip file, including images, you could try something like this: 
 
<?php 
require "zip.class.php"; 
$zipfile = new zipfile; 
$zipfile->read_zip("myzip.zip"); 
foreach($zipfile->files as $filea) 
{ 
    $fh = fopen($filea['name'], "w"); 
    fwrite($fh, $filea['data']); 
    fclose($fh); 
} 
?> 
 
If the file already exists, it will be overwritten.  If you need me to explain any code, just ask.  Note that the code I gave you does not preserve directory structure.  If you want this, I can give you the code. 
  
  Joe Adcock - 2009-01-28 11:38:04 -  In reply to message 1 from André Silva 
I am in need of a way of preserving the original file structure of the zip package. How is this possible? 
  
  sagar - 2009-02-04 13:05:57 -  In reply to message 2 from Joshua Townsend 
Hello 
 
     as you say in your post can you give me the code for "Preserve folder structure if unzipping the file" using this. 
 
Regards,     
  
  hero - 2009-09-08 12:46:22 -  In reply to message 2 from Joshua Townsend 
Hi Could you message me or post the way to retain folder structure. 
  
  Morris Mwanga - 2010-11-23 18:29:19 -  In reply to message 5 from hero 
How to retain folder structure 
 
<?php 
ini_set("memory_limit","1080M"); 
require "../zip.class.php"; 
$zipfile = new zipfile; 
$zipfile->read_zip("zip_file.zip"); 
foreach($zipfile->files as $filea) 
{ 
if(is_dir($filea['dir'])){ 
	$fh = fopen($filea['dir']."/".$filea['name'], "w"); 
} else { 
chdir(getcwd()); 
echo $filea['dir']; 
if(mkdir($filea['dir'])) { 
	$fh = fopen($filea['dir']."/".$filea['name'], "w"); 
		} 
	} 
fwrite($fh, $filea['data']); 
fclose($fh); 
} 
?> 
 
  
   |