views:

29

answers:

1

All,

I have a PHP5 application written with Zend Framework and MVC style. My application allows multiple users to login and see content based on their privileges. I have a dropdown on the home page. Upon selecting the dropdown, an ajax call occurs which populates the page with a table. Also, it generates a PDF file with the table data using mpdf library. There is a link called "Download PDF" in the page to allow the user to download the generated pdf.

My question is, in such environment, how to best serve pdfs to multiple users? Should I serve a single pdf with the a common name or should I create multple pdfs based on the dropdown value (looks like an overkill)? I don't want to let the users see each other's pdfs. Also, where should I store the pdfs as pretty much the entire application directory will have only 750 acccess.

Thanks,

+1  A: 
  • User clicks "downlod PDF"
  • Parameters like ID are sent with ajax
  • Is there a cached version of the PDF with that ID saved? Ok, show it to the user; else:
    • Generate PDF
    • Cache it
    • Show PDF to user

I would have a cache key like userid-documentid (user1-document1 for example) and name the document something that would make them recognize it in a "downloads folder": your-app document-name date.pdf (ABC Half year report 2010-07.pdf for example).

I would store the cache in a /tmp directory somewhere, and present the cached data with a custom header; the following is from Example 1 @ php.net:

<?php
header('Content-type: application/pdf');

header('Content-Disposition: attachment; filename="ABC Half year report 2010-07.pdf"');

readfile('/tmp/user1-document1');
chelmertz