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

[eluser]chefnelone[/eluser]
[quote author="Cristian Gilè" date="1294429416"]Do you call zip_files function from an anchor?
Please, paste here a reduction code of your controller and view.[/quote]
It is a little more complicated, is Ajax through jQuery when a form is submitted.

But for the test I'm not using the $_POST data sent for the ajax request. Just to be sure that the error is not generated for the data sent

js:
Code:
$('.form_class').live('submit', function(eve){
    eve.preventDefault();
          
    //console.log( $(this).serialize() );
        $.post(base_url + 'download/zip_files' , $(this).serialize() , function(html){
                
        });
    });

php:
Code:
function zip_files()
{
//NOT USING THE $_POST DATA
$this->load->library('zip');

$path = 'images/myImage.jpg';
//$this->firephp->log( $path  );
$this->zip->read_file($path);

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

}
#12

[eluser]Cristian Gilè[/eluser]
Have you tried to test it without ajax?

Code:
echo anchor('download/zip_files','download');
#13

[eluser]chefnelone[/eluser]
[quote author="Cristian Gilè" date="1294431144"]Have you tried to test it without ajax?

Code:
echo anchor('download/zip_files','download');
[/quote]

I tried http:localhost/mySite/download/zip_files
but get an error, something about MIME type:

ErrorException [ Warning ]: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/muestra3/application/controllers/download.php:26)

header('Content-Type: "'.$mime.'"');
#14

[eluser]Cristian Gilè[/eluser]
You echo something before download the zip!

Is the zip_files function exactly this?

Code:
function zip_files()
{
//NOT USING THE $_POST DATA
$this->load->library('zip');

$path = 'images/myImage.jpg';
//$this->firephp->log( $path  );
$this->zip->read_file($path);

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

}

Do you send some header in your controller constructor?
#15

[eluser]Cristian Gilè[/eluser]
You don't need ajax. You can remove the jquery script!
You can call download/zip_files directly.
Set the action form to 'download/zip_files'.

Cristian Gilè
#16

[eluser]chefnelone[/eluser]
[quote author="Cristian Gilè" date="1294433562"]You don't need ajax. You can remove the jquery script!
You can call download/zip_files directly.
Set the action form to 'download/zip_files'.

Cristian Gilè[/quote]

I really appreciate your time. I remove the js part and now is working like a charm!.

Thanks Cristian




Theme © iAndrew 2016 - Forum software by © MyBB