Hello
If I have a zip file located at on the hard drive, how do I extract the files from it to a specific location with php?
And while I'm at it I'd like to congratulate Sitepoint for the new web!
Thanks in advance!
| SitePoint Sponsor |





Hello
If I have a zip file located at on the hard drive, how do I extract the files from it to a specific location with php?
And while I'm at it I'd like to congratulate Sitepoint for the new web!
Thanks in advance!
Last edited by website; Feb 24, 2003 at 16:26.
- website





If you have the proper module installed and PHP 4.1.x or better you can use:
http://www.php.net/manual/en/function.zip-open.php
Otherwise, you may find some sample code at zend.com or phpclasses.org which work without special modules.





yeah, well, I already checkt out these functions but I just don't know how to actually write the files to the harddrive.?
- website


You might want to try using exec("cp (or copy, depending on your OS) X:\...\file.zip X:\...\( depending on your OS, again, you may have to put to.zip)")





Thanks for your replys but I don't think you understand what I have in mind.
Say I have a zip file called images.zip
In that file are say 3 files, image1.jpg, image2.jpg, image3.jpg.
The user uploads the file, I get the path to the temp file, I place it in a variable called $filetmp
Then I want to take each entry (image1.jpg, image2.jpg, image3.jpg) and save it to
wwwroot/images/
And then the zip file should be destroid (or just something)
I can't use move_uploaded_file (I think) or use Clete's suggestion because the images are inside the zip file. So how would I move image1.jpg to the predefined location?
Thanks in advance!
Last edited by website; Feb 26, 2003 at 17:59.
- website


Oh, sorry... I misunderstood. I thought you wanted to copy it to another location... again you will need exec() unless I'm missing a function... save the file, then try:
Works for mePHP Code:<?php
exec("unzip ". $filename);
exec("unlink ". $filename);
?>... I'll look into one that does not need exec...
I found this, though:
http://www.zend.com/zend/spotlight/...-zip-files1.php
http://www.zend.com/zend/spotlight/...-zip-files2.php
http://www.zend.com/zend/spotlight/...-zip-files3.php





Hmm, not quite getting this, exec, doesn't it just execute some commands on the os command line?
But there are some functions like zip_open zip_read but I just don't know how to acctually save each entry to the hard drive
And that Zend article is quite nice... except that they are doing the opposite of what I want![]()
- website





Hmm, I tryed it and there came no error, that at least is good sign. But how can I then move the files, I mean, you unzip it, then what? how would I save the files to some location? All advice or hints in the right direction I apreciate very much!Originally Posted by Clete2
- website
Bookmarks