I have a pdf file on disk that i need to send to a user when they make a request to a php script, what is the best way of doing this?
Thanks
I have a pdf file on disk that i need to send to a user when they make a request to a php script, what is the best way of doing this?
Thanks
Assuming that it's on the server:
Example from http://php.net/manual/en/function.readfile.php
Ok, so I’m no expert at PHP, I can only take credit for putting together a few other snippets of PHP to achieve what i needed it to do, and i thought i had better post this solution up in a few forums which asked the same question but i could not get to work myself. There did not seem to be a solution anywhere so here it is. It works for me... Ok so first off i created the PDF form and added a button which then submits form. In the actions of this submit form, i told it to PDF the complete document. Then i gave it a URL link to a php page, such as mail_my_form.php Then i created a php form, and named it the same as above... mail_my_form.php One last thing is to create a folder called pdfs in the root of where this php code will go. (So if you put the php in a folder called email, then inside the folder of email, you need another folder called pdfs) Now what this script does is: Saves the PDF to the file name pdfs. Then it attaches the file to an email and sends it. Then it deletes the file from the folder pdfs to save space. (you could take out the delete function to save your forms on your FTP also if you wanted to.
Here it is.
Hope this helps some of you.
Richard Williams
If you are using Apache or Lighty, then the "best" way to do this from a performance point of view, is to use the
X-Sendfile
header. See this tutorial: http://www.jasny.net/articles/how-i-php-x-sendfile/Here is what you need to send a file with PHP :
As Julian Reschke commented, the validated answer MAY work, but it's full of useless headers. The content-type should be set to the real type of the file, or some browsers (especially mobile browsers) may not download it properly.