| | |
Zip files and PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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
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
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
•
•
•
•
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!
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)
if(isset($_POST['upload'])){ $zip_dir = 'packs/zips/'; $license = $_POST['license']; $title = $_POST['title']; $title .= '_' . rand(999999,time()) . '.zip'; echo $title; $zip = new ZipArchive; $pack = fopen($zip_dir.$title,'wb'); fclose($pack); $zip->open($zip_dir.$title); $zip->addFile($license, 'newfile.txt'); $zip->close(); } ?> <form enctype="multipart/form-data" action="" method="post"> <?php if(file_exists('License.txt')) { $combo = '<select name="license">'; $combo .= '<option value="License.txt">License</option>'; $combo .= '</select>'; echo $combo; } ?>
Last edited by Ezzaral; May 20th, 2009 at 10:47 pm.
no dejes para mañana lo que puedes hacer hoy
•
•
Join Date: May 2009
Posts: 4
Reputation:
Solved Threads: 0
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!
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!
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:
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)
<?php $zip = new ZipArchive(); $filename = "./test112.zip"; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open <$filename>\n"); } $zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n"); $zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n"); $zip->addFile($thisdir . "/too.php","/testfromfile.php"); echo "numfiles: " . $zip->numFiles . "\n"; echo "status:" . $zip->status . "\n"; $zip->close(); ?>
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.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
•
•
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.
i have attached my error as an image.
and here is my code.
PHP Syntax (Toggle Plain Text)
<?php if(isset($_POST['upload'])){ $zip_dir = 'packs/zips/'; $license = $_POST['license']; $title = $_POST['title']; $title .= '_' . rand(999999,time()) . '.zip'; echo $title; $zip = new ZipArchive; if(!$zip->open($zip_dir.$title, ZIPARCHIVE::CREATE)) { echo 'Couldnt creat file'; }else { $zip->addFile($license, 'newfile.txt'); $zip->close(); } } ?> <form enctype="multipart/form-data" action="" method="post"> <?php if(file_exists('License.txt')) { $combo = '<select name="license">'; $combo .= '<option value="License.txt">License</option>'; $combo .= '</select>'; echo $combo; } ?> Title<input type="text" name="title"/> image:<input type="file" name="img" /> <input type="submit" name="upload" value="upload" onclick="javascript:self.location.reload();" /> </form>
no dejes para mañana lo que puedes hacer hoy
![]() |
Similar Threads
- zip files instead of jar (Java)
- Parsing Zip Files VB.Net (VB.NET)
- Uploading zip files (DaniWeb Community Feedback)
- Compress/Zip Files (VB.NET)
- Alternative to ZIP files needed - Any suggestions?? (IT Professionals' Lounge)
Other Threads in the PHP Forum
- Previous Thread: Need help in Php using Regular expression
- Next Thread: Playing a Powerpoint Presentation?
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl data database date directory display download duplicates dynamic echo email error execution file files folder foreach form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link links login loop mail menu mlm mod_rewrite multiple mysql oop parse paypal pdf php phpvotingscript problem query radio random recursion regex remote replace script search server session sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video volume web xml youtube






