Zip files and PHP

Reply

Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training
 
0
  #1
May 20th, 2009
I was wondering if it was possible to upload say a picture file and a text file and in the script put them into a zip file programatically.

if this is possible could you offer some tips or links please?

regards!

Thank you it looks like ill be reading for a while.
thanks again ,regards

Originally Posted by blur0224 View Post
This tells you everything you need to know about zipping with PHP.

http://us3.php.net/zip

Here is an upload tutorial you may find helpful.

http://www.tizag.com/phpT/fileupload.php

You'll have to create a file specific to the user, then add the two files, and finally send it to zip.


Good luck!
ok so to do a zip file through php. correct me if im wrong.

i use fopen to create a zip archive
fclose to close it
then use the ziparchive class to open it again
then use the addfile function to add a file to the archive.
then use close

but anywho, im getting an error when i try to unzip the folder, it is
0x80004005

any idea why this is?

ahh i c, sorry about that. so what should i do? keep posting here? or there.

anyways....my code

  1. if(isset($_POST['upload'])){
  2.  
  3. $zip_dir = 'packs/zips/';
  4. $license = $_POST['license'];
  5. $title = $_POST['title'];
  6. $title .= '_' . rand(999999,time()) . '.zip';
  7. echo $title;
  8.  
  9. $zip = new ZipArchive;
  10. $pack = fopen($zip_dir.$title,'wb');
  11. fclose($pack);
  12. $zip->open($zip_dir.$title);
  13. $zip->addFile($license, 'newfile.txt');
  14. $zip->close();
  15. }
  16. ?>
  17.  
  18. <form enctype="multipart/form-data" action="" method="post">
  19. <?php if(file_exists('License.txt'))
  20. {
  21. $combo = '<select name="license">';
  22. $combo .= '<option value="License.txt">License</option>';
  23. $combo .= '</select>';
  24. echo $combo;
  25. }
  26. ?>
Last edited by Ezzaral; May 20th, 2009 at 10:47 pm.
no dejes para mañana lo que puedes hacer hoy
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 4
Reputation: blur0224 is an unknown quantity at this point 
Solved Threads: 0
blur0224 blur0224 is offline Offline
Newbie Poster

Re: Zip files and PHP

 
0
  #2
May 20th, 2009
This tells you everything you need to know about zipping with PHP.

http://us3.php.net/zip

Here is an upload tutorial you may find helpful.

http://www.tizag.com/phpT/fileupload.php

You'll have to create a file specific to the user, then add the two files, and finally send it to zip.


Good luck!


Originally Posted by sacarias40 View Post
I was wondering if it was possible to upload say a picture file and a text file and in the script put them into a zip file programatically.

if this is possible could you offer some tips or links please?

regards!
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Zip File Help

 
0
  #3
May 20th, 2009
Wouldn't it be a good idea to re-use your previous thread which is still on the front page.

And if you post your code then people may be able to point out where you are going wrong.

Although, this is the example given by php.net:
  1. <?php
  2. $zip = new ZipArchive();
  3. $filename = "./test112.zip";
  4.  
  5. if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
  6. exit("cannot open <$filename>\n");
  7. }
  8.  
  9. $zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
  10. $zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
  11. $zip->addFile($thisdir . "/too.php","/testfromfile.php");
  12. echo "numfiles: " . $zip->numFiles . "\n";
  13. echo "status:" . $zip->status . "\n";
  14. $zip->close();
  15. ?>
Last edited by Will Gresham; May 20th, 2009 at 9:59 pm. Reason: Stupid code tags *mumble*
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,485
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Zip files and PHP

 
0
  #4
May 20th, 2009
Ok, my apologies, I tried to merge these two threads and it came out a bit of a mess. Hopefully something relevant can still be salvaged.
Last edited by Ezzaral; May 20th, 2009 at 10:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

Re: Zip files and PHP

 
0
  #5
May 20th, 2009
Originally Posted by Ezzaral View Post
Ok, my apologies, I tried to merge these two threads and it came out a bit of a mess. Hopefully something relevant can still be salvaged.
yeah i see that. oh well.

i have attached my error as an image.

and here is my code.

  1. <?php
  2.  
  3. if(isset($_POST['upload'])){
  4.  
  5. $zip_dir = 'packs/zips/';
  6. $license = $_POST['license'];
  7. $title = $_POST['title'];
  8. $title .= '_' . rand(999999,time()) . '.zip';
  9. echo $title;
  10.  
  11. $zip = new ZipArchive;
  12. if(!$zip->open($zip_dir.$title, ZIPARCHIVE::CREATE))
  13. {
  14. echo 'Couldnt creat file';
  15. }else
  16. {
  17. $zip->addFile($license, 'newfile.txt');
  18. $zip->close();
  19. }
  20. }
  21. ?>
  22.  
  23. <form enctype="multipart/form-data" action="" method="post">
  24. <?php if(file_exists('License.txt'))
  25. {
  26. $combo = '<select name="license">';
  27. $combo .= '<option value="License.txt">License</option>';
  28. $combo .= '</select>';
  29. echo $combo;
  30. }
  31. ?>
  32. Title<input type="text" name="title"/>
  33. image:<input type="file" name="img" />
  34. <input type="submit" name="upload" value="upload" onclick="javascript:self.location.reload();" />
  35.  
  36.  
  37.  
  38. </form>
Attached Thumbnails
error.jpg  
no dejes para mañana lo que puedes hacer hoy
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC