Link to home
Start Free TrialLog in
Avatar of epdass
epdass

asked on

how to create zip file on fly

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.
ASKER CERTIFIED SOLUTION
Avatar of spiffen
spiffen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of epdass
epdass

ASKER

hi

i will look into it and then i revert you back
Avatar of epdass

ASKER

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
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:  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp  
waiting
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.
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:
https://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
split the point
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