I want to serve invoices for download. Currently I'm using a simple numbering scheme (invoice-01.pdf, invoice-02.pdf, and so on). I know that I could use hashes instead to obscure the data.
Is it also possible to use PHP and serve the invoices by not directly having the user point to them?
There is even an example of this on php.net
Or expand that a bit with
Sam has the answer. Also put them in a directory with .htaccess:
That will keep out direct access if they know the url. You can still read it from your PHP script with readfile().
I found for this excellent guide: How to serve big files through PHP.
Especially useful is the lighttpd trick - If your PHP happens to run under lighhtpd, script only needs to set "X-Sendfile" header, and lighttpd will read and send the file for you (and it well knows how to send files).
UPDATE:
(Quoted from NginX documentation)
My function with automatic MIME type detection :
usage :
Pay attention to not send anything else with PHP (no echo).