Solved

how to create zip file on fly

Posted on 2001-06-19
10
1,705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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