Login   Register  
PHP Classes
elePHPant
Icontem

Zip folder and its files and download

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Zip  >  All threads  >  Zip folder and its files and download  >  (Un) Subscribe thread alerts  
Subject:Zip folder and its files and download
Summary:Zip folder and its files and download
Messages:7
Author:Daniel Simões
Date:2014-07-17 17:46:23
Update:2014-07-17 23:15:27
 

  1. Zip folder and its files and download   Reply   Report abuse  
Picture of Daniel Simões
Daniel Simões
2014-07-17 17:46:23
Hi!

I have a folder for each client.
Each folder has multiple images inside.

How can i zip a given folder and all images?

I have tried this

include_once("ZipStream.php");

$zip = new ZipStream("photos.zip");

$files = scandir('example/');
foreach ($files as $path){
$zip->add_file($path, file_get_contents($path));
}
$zip->finish();

Thanks.
Daniel

  2. Re: Zip folder and its files and download   Reply   Report abuse  
Picture of Asbjorn Grandt
Asbjorn Grandt
2014-07-17 18:54:41 - In reply to message 1 from Daniel Simões
Doesn't the addDirectoryContent function work for you?

public function addDirectoryContent($realPath, $zipPath, $recursive = true, $followSymlinks = true, &$addedFiles = array(),

Examlple:

$zip->addDirectoryContent("example/","images");

  3. Re: Zip folder and its files and download   Reply   Report abuse  
Picture of Daniel Simões
Daniel Simões
2014-07-17 20:52:28 - In reply to message 2 from Asbjorn Grandt
Hi! Thanks for the quick reply!

I changed my code to this:

include_once("ZipStream.php");
$zip = new ZipStream("photos.zip");
$zip->addDirectoryContent("example/","images");
$zip->finish();

But:
1. When i try to unzip the .zip i get the invalid format error;
2. It only adds the first image in the folder. And the folder has something like 500 images. And still the imagem is in invalid format.

Im running the code in IIS 7, windows server 2008
And it is php version 5.3

Can you help me?

Thanks again,
Daniel.

  4. Re: Zip folder and its files and download   Reply   Report abuse  
Picture of Asbjorn Grandt
Asbjorn Grandt
2014-07-17 22:15:39 - In reply to message 3 from Daniel Simões
If you are allowed, can you send me the defective zip to php@grandt.com?

I've never run PHP on Windows, so I can't say what that might do, but it could affect the way paths are handled.

$zip->addDirectoryContent("example/","images");
should probably be changed to
$zip->addDirectoryContent("example" . DIRECTORY_SEPARATOR,"images");



I just ran this script on my own server:

<?php
error_reporting(E_ALL | E_STRICT);
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 1);

include_once("ZipStream.php");

$zip = new ZipStream("test3.zip");
$zip->addDirectoryContent("testData" . DIRECTORY_SEPARATOR,"test");
$rv = $zip->finalize();
?>

It correctly created a zip file with everything in the test directory, and its sub directories. test is in this case placed in the same dir as the ZipStream example script.
Though only 26 files, they make up about 74MB

  5. Re: Zip folder and its files and download   Reply   Report abuse  
Picture of Daniel Simões
Daniel Simões
2014-07-17 22:48:56 - In reply to message 4 from Asbjorn Grandt
Hi!

I sent you the zip file and some more info for your email.
Can we communicate by email now?


Thanks for the help again!
Daniel.

  6. Re: Zip folder and its files and download   Reply   Report abuse  
Picture of Asbjorn Grandt
Asbjorn Grandt
2014-07-17 23:01:04 - In reply to message 5 from Daniel Simões
We can, though it'll be a few hours before I can continue. It's 1 past midnight here :)

  7. Re: Zip folder and its files and download   Reply   Report abuse  
Picture of Daniel Simões
Daniel Simões
2014-07-17 23:15:27 - In reply to message 6 from Asbjorn Grandt
Off course, no problem!
Its late in Portugal too :)

I can wait.. this is for a web app im currently working, but its not crucial


Thanks again,
Daniel.