Solved

how to create zip file on fly

Posted on 2001-06-19
10
1,685 Views
Last Modified: 2008-02-26
hi every body

I am doing programming in php,in which user can able to select the one or more files to download. I want to give the selecting files into zip format to user. How can i do this.

i.e,

check box: file1
check box: file2
check box: file3
check box: file4

submit -> somename.zip(which has to download to user)

Can anyone help me out.
0
Comment
Question by:epdass
  • 3
  • 3
  • 2
  • +1
10 Comments
 

Accepted Solution

by:
spiffen earned 50 total points
ID: 6206712
It depends a bit on what operating system you are running php on. However.. Using the exec() command should to it..

If linux:
exec("zip -0 packedfile.zip file1.txt file2.txt");

If windows:
exec("pkzip -a packedfile.zip file1.txt file2.txt");

Which requires the pkzip to be in PATH..

Writing the whole thing takes too long. But a tip is to
name the checkboxes <input type="checkbox" name="FILE:myfile.txt"> then when submitting (loading the file that sends the file) use:

<?php // file is i.e sendfile.php
$zipfile = "files.zip"; // the name of the zip we create.
while (list($var, $value) = each($HTTP_POST_VARS)) {
 if(substr($var,0,5)=="FILE:") { // is it our checkboxes?
  $tmparr = explode(":",$var); // split at :
  $filename = $tmparr[1]; //filename shouldbe "myfile.txt"
  $filestoadd .= $filename." ";
 }
}

exec("pkzip -a $zipfile $filestoadd");
header("Content-type: application/download");
header("Content-Length: ".filesize($zipfile));
header("Content-Disposition: inline; filename=$zipfile");
header("Content-Transfer-Encoding: binary");
readfile($filename); // Send it
unlink($filename); // delete it
die();
?>

Good luck. I never tested this code but I hope you
got some nice ideas..
/Spiffen
0
 
LVL 8

Expert Comment

by:us111
ID: 6209392
look spiffen comment:

<?
$ZIPATH="/somewhere";
$f = "file.zip";
exec("zip -0 $ZIPPATH/$f file1.txt file2.txt");

$d = @fopen("$ZIPPATH/$f","r");

if (!$d)
{     // If file cannot be read or not available ...
     print "<HTML><BODY><H1>Failed to download $f !!!</H1></BODY></HTML>";
}
else
{     header("Content-Type: application/octet-stream");
     header("Content-Length: ".filesize("$ZIPPATH/$f"));
     header("Content-Disposition: attachment; filename=" .basename("$ZIPPATH/$f"));
     $data="";
     while (!feof($d)) $data.=fread($d,12400);
     fclose($d);
     print $data;
 }

it works
0
 

Author Comment

by:epdass
ID: 6210548
hi

i will look into it and then i revert you back
0
 

Author Comment

by:epdass
ID: 6224493
Hi spiffen

Thanks for your nice reply.

I tried your program. It starts download,but arguments are not correctly passed to function. i.e., the zip file is blank. It don't have no files. I checked the path of given files even it's not working. Can you try it for me and send me the feedback. I eagerly waiting for your reply.

Cheers
epdass
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6419164
It's time to clean up this topic area and that means taking care of this question. Your options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

3.  Ask Community Support to help split points between participating experts.  Just comment here with details.

4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.

PLEASE DO NOT AWARD THE POINTS TO ME.

____________________________________________



Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.

Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.

Thank you everyone.

Moondancer :)
Community Support Moderator @ Experts Exchange

P.S.  REGARDING POINTS, Guidelines and more:  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp  
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Expert Comment

by:us111
ID: 6421055
waiting
0
 

Expert Comment

by:spiffen
ID: 6423915
Oh man. I totally forgot about this topic. :)
Well.. To the question. My example was based on having the files to be zipped in the same directory as the .php doing the exec().. And yes. It worked for me..

You could try to experiment further on with using full path to each file that should be included in the zip.

.. And correct me if Im wrong. But you should have solved the problem by now since it was 2 months ago.. :)

Well.. Sorry about forgetting the topic.
Good luck.

/Regards Spiffen.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6699540
ATTN:  epdass

You have asked 43 questions at this site and only closed 26 of them.  You do not remain active with pertinent responses to the experts who have stepped in to help you.  I will be updating all your open questions and monitoring them for closures.  Please do the following:

1)  Add comments to the experts as to your progress and/or what else is needed, if still unresolved .. or ..
2)  Award the expert who helped you and grade them to close the item.  If more than one helped you, open a question here for zero points, include the link and the expert names and amounts you want to award:
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
3)  Bring any special requests to our attention at the above link that varies from the above processes, or if you have any questions about this site and the guidelines of use.  

Please, again, read the Agreement and site Guidelines, both available from the Help Desk link on the left.  When you signed up for experts-exchange, you agreed to the criteria outlined therein.

Your responsiveness and timely handling of your questions is not only appreciated, but needed.  I will monitor progress for one week, and if still unresolved and inactive will need to decide the outcome.  Expert input is always welcome to determine the outcome.

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 8

Expert Comment

by:us111
ID: 6700188
split the point
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6700312
Points have been split, one awarded here, the other:

Points for us111 .. qid=20249905  .. this topic area.  Please comment to complete this other half.

Sorry you had to wait so long.

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now