Re: ZIP it :o)
| From: | Jim Lucas | Date: | Fri, 01 Jun 2007 16:21:07 +0000 |
| Subject: | Re: ZIP it :o) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255974@lists.php.net to get a copy of this message | ||
Tijnema wrote:
On 6/1/07, Jim Lucas <lists@cmsws.com> wrote:Now what?Tijnema wrote:On 6/1/07, Jim Lucas <lists@cmsws.com> wrote:Yes, but what happens when you try to create a 1GB archive with 512MB RAM? (and no swap space too) or if 100s of people call the same script that creates a 10-20MB file? If you use the exec way, this will go fine :) Unless you have a disc quota that you come up against.Hi guys, thanks to Jim, I made it :o) Here's the source I'm using for testing now... it works. I just need to make it less vulnerable ;o) ----- SNIP ----- <? $nr = $_GET['nr']; if(eregi("../", $nr)) { die("Hier wird nicht rumgehackt"); } $directory = '_kfz_images/'.$nr.'/full/'; $dir = opendir($directory); $i = 1; while($file = readdir($dir)) { $dest = "temp/Auto-Deppe-".$nr."_".$i.".jpg"; if(eregi("jpg", $file)) { copy($directory.$file, $dest); $i++; } } $now = time(); header("Content-Type: application/force-download"); header('Content-Disposition: attachment; filename="Auto-Deppe-'.$now.'_Download.zip"'); exec("zip ".$now."_archive.zip temp/* 2>&1", $output); readfile($now."_archive.zip"); $tempdir = opendir("temp"); while($tempfile = readdir($tempdir)) { if(eregi("jpg", $tempfile)) { unlink("temp/".$tempfile); } } ?> ----- SNAP ----- So I am copying the files to a temp dir, and then zip em up, deleteAuto-Deppe, C. Haensel wrote:afterwards. I copy them to the dir so I wouldn't have the whole /kfz_images/number/full/ structure in the zip). Aaaanyhow, it works, it does work fast enough, and I am happy :o) Thanks a bunch, guys, and have a great day! This is Christian Haensel live from Extertal, Germany. Back to you. -:oD)= ----- Original Message ----- From: "Tijnema" <tijnema@gmail.com> To: "Chris" <dmagick@gmail.com> Cc: "Auto-Deppe, C. Haensel" <c.haensel@auto-deppe.de>; <php-general@lists.php.net> Sent: Friday, June 01, 2007 9:27 AM Subject: Re: [PHP] ZIP it :o)themarchive onMorning guys, I have been trying to find an easy to use way to zip anOn 6/1/07, Chris <dmagick@gmail.com> wrote:Auto-Deppe, C. Haensel wrote:$directorybox running PHP5. Now I've tried the zip-lib.php and others, buta > linuxtheyalways throw an error msg.... But that is not the question. I am looking to use exec("zip archive.zip $directory");ask youbeen tried with both full path and relative path ... but that doesn'thasdon't get an error, it just doesn't create the zip-file... So, after a day of Google-ing and trying, I thought I mightwork. > IPHP, ihelp. Cheers for any answers and hints.forexisting onehttp://pear.php.net/package/Archive_Zip and/or http://pear.php.net/package/File_Archive and please create a *new* message instead of replying to anclientsand changing the topic. It screws up message threading (in emailand in the archives).Not in gmail :) I had same problem lately, wanted also to create zip files fromwritetried various build in functions, but i ended up with the exec way. It has been said before, but PHP probably doesn't have the right permissions to write the .zip file, so i would recommend you toto /tmp first. Tijnema"--with-zlib"Here's a link to the zip class that I use http://www.phpclasses.org/browse/package/945.html One thing though, your PHP install has to be compiled withThat was the only thing that I ran into with this. Since you are creating files to download, with this class, you don't even need to write them to the filesystem. You just create the archive in memory (given that you have enough RAM && php is allowed to consume as much memory as it would take the create the archive) and then dump it to the browser
Tijnemaimho, not all limitations are negative limitations force you to think about a more creative way to solve the problem at handnever said it would be the ops solution, but that it was my solution.Nope, you didn't but you noted the difference in speed for both, but you didn't note any problems that could occur.But isn't it nice to be able to know about different options that one might have to solve a given problem? -- Jim LucasSure it is, but don't forget to note the negative things of the option.! imho, this is not a negative thing, it is more of a limitation.
Tijnema-- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Unknown