1

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

4 Answers 4

2

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 ;-)

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

thanks for replying is there any link for the same where i can check?
1

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

2 Comments

but i want to generate 5 pdfs & how to add it to a single zip file
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.
1

I used the flowing code in my php page:

 if(isset($_GET['get_pdf'])){
     $query = "SELECT * FROM tbl_fixation WHERE postedby = '$name_user' ORDER BY fixation_id ASC ";
      $data_query = $hrmdb->select($query);
      if($data_query ){
        $i=0;
        while ($rows= $data_query ->fetch_assoc()) {
          $i++;
          $fixation_id = $rows['fixation_id']; 
echo "<script> window.open('allpdf/single_letter_fixation.php?fixation_id=".$fixation_id."','_blank');</script>";  
    }}
     }

Output option for pdf file in single_letter_fixation.php is:

$pdf->Output('D', $personal_file_number.pdf');

It works well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.