Welcome Guest, Not a member yet? Register   Sign In
How to zip 2 images files and download the zip file?
#1

[eluser]chefnelone[/eluser]
Hello,

I found this in the user guide to zip an existing file, works fine but just with one file.

Code:
$path = '/path/to/photo.jpg';

$this->zip->read_file($path);

$this->zip->download('my_backup.zip');

I need to zip 2 files and then download the zip file. Something like ( the code below is not working.. just to give an idea of what I need to do)
Code:
$path1 = '/path/to/photo.jpg';
$path2 = '/path/to/photo2.jpg';

$data = array($path1, $path2);

$this->zip->read_file( $data );

$this->zip->download('my_backup.zip');  // this zip file contains both photos
thanks
#2

[eluser]Cristian Gilè[/eluser]
Hi chefnelone,

you can use $this->zip->read_dir() that permits you to compress a folder (and its contents) that already exists somewhere on your server.

Code:
$path = '/path/to/your/directory/'; //path where are stored your two files

$this->zip->read_dir($path);

// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
#3

[eluser]chefnelone[/eluser]
[quote author="Cristian Gilè" date="1294419861"]Hi chefnelone,

you can use $this->zip->read_dir() that permits you to compress a folder (and its contents) that already exists somewhere on your server.

Code:
$path = '/path/to/your/directory/'; //path where are stored your two files

$this->zip->read_dir($path);

// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
[/quote]

I see, but the folder containing the images has another images that I don't want to include in the zip.
I think I'll need to create a folder, move the images to this folder, then use $this->zip->read_dir($path); and delete the folder after.

I believe that de Zip class should include a function to do this task this simpler...
#4

[eluser]Cristian Gilè[/eluser]
Code:
$path = 'path/to/file1';

$this->zip->read_file($path);

$path = 'path/to/file2';

$this->zip->read_file($path);

// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
#5

[eluser]chefnelone[/eluser]
Rare, suddendly the zip class stop working

if i try this code: I get rare characters as you can see in this image:
image
Code:
function zip_files()
{
  $this->load->library('zip');

  $path = '/images/myImage.jpg';

  $this->zip->read_file($path);

  // Download the file to your desktop. Name it "my_backup.zip"
  $this->zip->download('my_backup.zip');

}

Something to do with my server (I'm on localhost running on MAMP)???
#6

[eluser]Cristian Gilè[/eluser]
Don't echo nothing before zip file!
#7

[eluser]chefnelone[/eluser]
[quote author="Cristian Gilè" date="1294426390"]Don't echo nothing before zip file![/quote]

nothing just the output through Firebug you can see in the image... rare it was working fine, maybe my server???

I have Firephp to output whatever info from the function zip_files, if this helps...
#8

[eluser]Cristian Gilè[/eluser]
The rare character you see is the zip file output in the debug firephp var.
Probably is a buffering output problem. Try do disable firephp or check if the directive output_buffering is On in your php.ini conf file and set it to Off.
#9

[eluser]chefnelone[/eluser]
[quote author="Cristian Gilè" date="1294428098"]The rare character you see is the zip file output in the debug firephp var.
Probably is a buffering output problem. Try do disable firephp or check if the directive output_buffering is On in your php.ini conf file and set it to Off.[/quote]


output_buffering is set to Off
I disabled Firephp

I also restart my server (MAMP)

but nope.... still not working
#10

[eluser]Cristian Gilè[/eluser]
Do you call zip_files function from an anchor?
Please, paste here a reduction code of your controller and view.




Theme © iAndrew 2016 - Forum software by © MyBB