tags:

views:

118

answers:

3

Hi,

I have added a link on a page clicking on which generates a pdf and asks for download for which i have used fpdf class.

My new requirement is that clicking on the link should generate n number of pdf with different content and should ask for downloading these pdfs.

I am unable to find out the method to accomplish the same.

Please help me on this.

Thanks

A: 

You can't send multiple files to user but you can generate them, pack with e.g. zip on server and send as one file.

Piotr Pankowski
@piotr thanks for replying is there any link for the same where i can check?
Pankaj Khurana
A: 

The correct method to send your generated file to the browser is the $pdf->Output() - this will only allow you to send one generated pdf file. The only option to send more files is to zip them [1] and then send the package file.

[1] http://www.devco.net/archives/2005/05/24/creating_zip_files_with_php.php

dhh
Pankaj Khurana
Simple : you create the PDFs one by one, add them to a single ZIP and finally send that ZIP as output. BTW You can use any archive format of course, it doesn't have to be ZIP.
wimvds
+1  A: 

At http://www.phpconcept.net/pclzip/ you'll find a nice php zip library. Imagine having an array of filenames like

$filenames = array(
    "file_01.txt",
    "file_02.doc",
    "file_03.pdf"
);

the code would look like this (untested)

require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
foreach($filenames as $filename) {
    $result = $archive->add($filename);
    if($result==0) {
        die ("Error: " . $archive->errorInfo(true));
    }
}
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=archive.zip");
readfile("archive.zip");

Hope this helps ;-)

dhh