Michael Martin-Smucker
Michael Martin-Smucker

Reputation: 12705

Can PHP handle a PDF form submitted as a complete PDF document

In Short:

I have a PDF that customers can fill out. When they press the "Submit" button, I want to automatically send an email with the completed PDF attached. This should happen server-side with no further interaction from the customer.

In Long:

Currently I have the PDF set to post the data to the server as html form data. My PHP script then processes this data and sends a plain text email with the data. The people receiving the email would prefer to have a copy of the actual PDF, not just plain text.

So, in Adobe Acrobat 9 Pro, I set the Submit button to submit as "PDF The complete document" (as seen below).

enter image description here

The problem is, I don't know what to do in PHP to handle this. I assumed it would upload to the server as part of the $_FILES array, but print_r($_FILES) shows an empty array, and the count of both $_FILES and $_POST is 0.

So my question is, what's happening to the uploaded pdf? and is there anything I can do with PHP to turn that pdf into an email attachment? I don't think I'm running into issues with the file size; the post_max_size is 2MB, and the PDF is only about ~725kb.


I actually ended up sending the FDF data to the server instead of the whole PDF. This meant I had to write a whole bunch of gibberish into my PHP to handle the FDF, but all-in-all it's a smaller upload and it meets the customer's requirements. If you really need to upload the whole PDF, Patrick's answer below should be correct -- you should be able to find the uploaded pdf in $GLOBALS['HTTP_RAW_POST_DATA'].

Upvotes: 1

Views: 3812

Answers (1)

pat o.
pat o.

Reputation: 140

You can pull the raw PDF data from $GLOBALS['HTTP_RAW_POST_DATA']. You can output this to a file and open it as you would any PDF.

Upvotes: 1

Related Questions