Creating zip files via ajax jquery in php

hi ,
i m creating a zip file of bunch of files . i m sending request via ajax by using jquery . but zip file gives output of few of ascii characters . it doesn’t generate the zip file . but when i test it separately . it works fine . but not with ajax .

looking forward
Thanks

$zipfile = new Ziplib;
$zipfile->zl_add_file($stringData,$_REQUEST['filename'],"g9");
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\\"testfile.zip\\"");
echo $zipfile->zl_pack("zip file comments");

this is jquery code

$.ajax({
                                                                           url:'create_page.php',
                                                                           type:'POST',
                data:'header=' + $('#p_header').val() + '&filename=' + $('#p_filename').val() + '&footer=' + $('#p_footer').val() + '&path=' + $('#p_path').val() + '&page_view=' + $('input[name=page_way]:checked').val() + '&tut_values=' + checkSegmentStatus2,
                                                                           success:function(results)
                                                                           {
                                                                                   $('#loading_img').remove();
                                                                                 alert('Your page has been created!');
                                                                                  alert(results);
        //                                                        $('#loading_div').append('<img src="images/loading.gif" alt="Generating the demos page ..." id="loading_img" />');

                                                                                   }

does the $_REQUEST[‘filename’] variable contain the value you expect it to?

$_REQUEST[‘filename’]=name of the file that will be included in zip archive.

I know what you think it is, but I’m asking you what it actually is.

You can use var_dump() to see the value of your variables.

i have tried with dummy values too like this
$zipfile->zl_add_file(“it is a testing file”,“demo.html”,“g9”);

I thought you said it works fine when tested seperately?

it works fine when i run just the php code . but when an ajax call is made then ,u remember there is echo statement that outputs the zip archive to download , it shows ascii characters instead of force download of zip archive .

Oh my bad, I completely glazed over how you’re trying to download the file. No need to use ajax here.

You can submit a form, or just give them a link to click.

i have to use the ajax here , because , in my application i m generating html pages and then i have to make them all in zip archive for download.

did u got my point ?

No, you definately don’t need to use ajax to download the zip. In fact, I don’t think you can.

is it possible to store the zip on the server , instead of download ?

Yes. See file_put_contents()

how to use file_put_contents() to make zip file ?

i tried this but doesn’t work … it creates the file but it says it is damaged or data is not formatted.

file_put_contents(“test.zip”,include(“index.php”));