Can PHP handle a PDF form submitted as a complete

2019-03-01 12:15发布

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'].

2条回答
聊天终结者
2楼-- · 2019-03-01 12:58

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.

查看更多
等我变得足够好
3楼-- · 2019-03-01 12:58

If your $_FILES array is empty, you probably are using wrong <form enctype=""> attribute value. Check if you have:

enctype="multipart/form-data"

This is required for form to allow sending files. Then you can use uploaded file and send it to the client, which seems that you are capable of.

查看更多
登录 后发表回答