943,865 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1079
  • PHP RSS
May 20th, 2009
0
Re: Zip files and PHP
Expand 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!

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

Click to Expand / Collapse  Quote originally posted by blur0224 ...
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

php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 11
Solved Threads: 4
Junior Poster
sacarias40 is offline Offline
113 posts
since Nov 2008
May 20th, 2009
0

Re: Zip files and PHP

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!


Click to Expand / Collapse  Quote originally posted by sacarias40 ...
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!
Reputation Points: 10
Solved Threads: 3
Light Poster
blur0224 is offline Offline
37 posts
since May 2009
May 20th, 2009
0

Re: Zip File Help

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:
php Syntax (Toggle Plain Text)
  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*
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
May 20th, 2009
0

Re: Zip files and PHP

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
May 20th, 2009
0

Re: Zip files and PHP

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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.

PHP Syntax (Toggle Plain Text)
  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
Click image for larger version

Name:	error.jpg
Views:	19
Size:	111.1 KB
ID:	10184  
Reputation Points: 11
Solved Threads: 4
Junior Poster
sacarias40 is offline Offline
113 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Need help in Php using Regular expression
Next Thread in PHP Forum Timeline: Ex-Cel updation?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC