PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 9th, 2003, 09:26 AM
mickro's Avatar
mickro mickro is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Birmingham, UK
Posts: 56 mickro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 5 sec
Reputation Power: 9
Send a message via AIM to mickro
zlib Multiple files in one archive

Hi All,

Is it possible to Zip up more than one file into a single .gz file using zlib?

I have been trying the following code which does not seem to work:
PHP Code:
function compress($filename,$filename2) {        
    
$fp fopen($filename,"rb");
    
$data fread($fp,filesize($filename));
    
fclose($fp);

    
$fb fopen($filename2,"rb");
    
$data2 fread($fb,filesize($filename2));
    
fclose($fb);
    
    
$fd fopen("$filename.gz","ab");
    
$gzdata gzencode($data,4);
    
$gzdata2 gzencode($data2,4);
    
fwrite($fd,$gzdata);
    
fwrite($fd,$gzdata2);
    
fclose($fd);
    return 
"$filename.gz";



Any ideas would be much appreciated

Cheers

Mike

Reply With Quote
  #2  
Old August 19th, 2003, 07:54 PM
dreamchimney dreamchimney is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 3 dreamchimney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
any luck ?

im trying the same thing! did you solve this problem?

im using gzwrite instead of gzencode

Reply With Quote
  #3  
Old August 20th, 2003, 05:18 AM
mickro's Avatar
mickro mickro is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Birmingham, UK
Posts: 56 mickro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 5 sec
Reputation Power: 9
Send a message via AIM to mickro
Hi dreamchimney,

I found a class which does it well (see attached). Usage is by the following code:

PHP Code:
<?    
    
require("includes/zip.lib.php");    
    if (isset(
$_POST['action'])) {
        
$name str_replace(" ","_",$_POST["name"]); // replace spaces in filename otherwise won't work
        
$cvfile "cvtemp/$name/cv_" str_replace(" ","_",$resume_name);
        
$letterfile "cvtemp/$name/letter_" str_replace(" ","_",$letter_name);
        
mkdir("cvtemp/" $name); // create temporary folder to hold files to be zipped
        
copy($resume,$cvfile); // copy posted cv file to temp folder
        
copy($letter,$letterfile); // copy posted letter file to temp folder
        
$z = new PHPZip();
        
$z -> Zip("cvtemp/$name""zip/$name.zip"); // zip up contents of temp file
        
rmdir("cvtemp/$name"); // remove temp file
    
}
?>

<form name="upload" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">
<table cellpadding=0 cellspacing=0 summary="upload table">
    <tr>
          <td>Name:</td>
          <td><input name="name" size="30" maxlength="60"></td>
    </tr>
    <tr>
          <td>E-mail:</td>
          <td><input name="email" size="30" maxlength="60"></td>
    </tr>
    <tr>
          <td>Resume:</td>
          <td><input type="file" name="resume"></td>
    </tr>
    <tr>
          <td>Cover Letter:</td>
          <td><input type="file" name="letter"></td>
    </tr>
    <tr>
          <td colspan="2" align="right"><input type="submit" class="submit" name="action" value="Send"></td>
    </tr>
</table>
</form>


You will need to alter the code to meet your specific needs but this should get you going.

HTH

Mike
Digital Egg Ltd
Attached Files
File Type: php zip.lib.php (7.1 KB, 272 views)

Reply With Quote
  #4  
Old December 11th, 2003, 02:05 PM
jbuckle24 jbuckle24 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Burlington, VT
Posts: 343 jbuckle24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 43 m 53 sec
Reputation Power: 0
Facebook
hello,

just wondering where you found the file you attached? Was there any more documentation than what was provided? This will be very helpful, but I was wondering if their was a way to unzip the folder aftwerwards?

thanks,
-jbuckle24

Reply With Quote
  #5  
Old December 11th, 2003, 02:35 PM
realnowhereman realnowhereman is offline
Not there when you need me
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2001
Location: Berlin, Germany
Posts: 1,433 realnowhereman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 46 sec
Reputation Power: 10
Folks, fyi ...

A gzipped file contains exactly one file. The usual way to use gzip compression on several files is to put them into a tar archive, which can be done using Archive_Tar ( http://www.devshed.com/Server_Side/...File/page1.html) and to compress the tar file.

HTH

Reply With Quote
  #6  
Old December 12th, 2003, 01:15 PM
holroy's Avatar
holroy holroy is offline
A happy helper
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Stavanger, Norway
Posts: 458 holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 6 h 29 m 6 sec
Reputation Power: 7
Quote:
Originally posted by realnowhereman
Folks, fyi ...

A gzipped file contains exactly one file. The usual way to use gzip compression on several files is to put them into a tar archive, which can be done using Archive_Tar ( http://www.devshed.com/Server_Side/...File/page1.html) and to compress the tar file.

HTH


Not necessarily correct! Look at http://www.ietf.org/rfc/rfc1952.txt . This clearly states in section 2.2 on file formats:
Quote:
2.2. File format

A gzip file consists of a series of "members" (compressed data sets). The format of each member is specified in the following section. The members simply appear one after another in the file, with no additional information before, between, or after them.


Albeit I'll agree that the usual way is to do the tar first, and then gzip the result. And this does also provide proper handling of filenames and directories and stuff.

As for alternatives, it's not so hard to produce a proper zip file, either using the zlib or (gzip on unix when no zlib available), and neither to process this zipped file. For starters on the format to use, see http://www.pkware.com/products/ente...ers/appnote.txt

I've build my own zip/unzip classes already, but they only uses in-memory files, and are not for public view. At least not yet, but I'm seriously thinking of producing zip/unzip classes loosely build on top of zlib. Time will show if I will publish these scripts/classes or not.

But back to the original problem, if adding several members (that is several gzdeflated files) into one file, then you need a proper tool to decompress them, and I'm not sure how zlib handles that. But it's possible, so keep trying.

<e><

Reply With Quote
  #7  
Old December 12th, 2003, 02:08 PM
realnowhereman realnowhereman is offline
Not there when you need me
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2001
Location: Berlin, Germany
Posts: 1,433 realnowhereman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 46 sec
Reputation Power: 10
You're right, several files are possible. However, gzip considers several members in an archive to be concatenated data. Do other programmes handle that differently?

Thanks for the links.

Reply With Quote
  #8  
Old December 14th, 2003, 09:28 AM
holroy's Avatar
holroy holroy is offline
A happy helper
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Stavanger, Norway
Posts: 458 holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level)holroy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 6 h 29 m 6 sec
Reputation Power: 7
I've not studied very well which programs does what, but I know that within the header of each member there are (optional) fields to tell the filename. But I don't know which programs (if any/all) sets this filename, and I don't know how cares when reading the file.

As such, it is much wiser to use the tar.gz-format which is publicly known mainly within the unix community, but at a steadily higher degree in Windows as weel (through the use of WinZip, at least). Or to use the PK Zip-file format, which is understood on both platforms.

Sorry for not including references to Mac here, but I haven't used that to any extent, but I have a faint idea that the PK Zip-file format is a little more known than tar.gz. What (I think) I do know is that the Mac format of .sit or .hqx(?) are not that widely supported the other way around. (Although WinZip gets most of what you throw at it... )

<e><

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > zlib Multiple files in one archive


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
Stay green...Green IT