Ok, here goes...(EXTREME novice here)...
I have currently a PDF form with a submit button set to deliver the form as a PDF to a script on a server. The script is very basic; it reads 'php://input' and places the PDF info back into a PDF 'template' that it then emails out to recipients as attachments. This is working fine, EXCEPT... What I would like to do is extract the values of two variables within the submitted PDF (like 'FirstName' & 'LastName') and use them as the new file name (for the PDF that gets emailed).I currently have a static name for all PDFs that get emailed.
I use to send as FDF (also from a PDF form submit) to a different script that would allow me use _$POST variable values for the names of resulting FDF file attachments. I cannot figure out how in the world to get the information I need from 'php://input' to do the same for PDF files.
Here's a snippet. I hope someone out there can help. Thanks ahead of time!:
//set timezone
putenv("TZ=America/Los_Angeles");
//read stream
$pdfAttachment = file_get_contents('php://input');
$fp = fopen( 'empty.pdf', 'wb' );
fwrite( $fp, $pdfAttachment );
fclose( $fp );
//name for emailed pdf
$pdfname = date("m.d.y \_ h:i a").'.pdf';
//define the receiver of the email
$to = 'email@xxxxx.com' . ', ';
$to .= 'email@xxxxx.com';
//define the subject of the email
$subject = 'Enrollment Application Submitted';
//create MD5 boundary string
$random_hash = md5(date('r', time()));
//define headers
$headers = "From: email@website.net\r\nReply-To: email@website.net";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read, encode and split
$attachment = chunk_split(base64_encode($pdfAttachment));
//define the body of the message.
ob_start(); //Turn on output buffering
//more email stuff here....
//Here is the attached PDF part
//attachment named '$pdfname' (currently set as timestamp-see above)
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/pdf; name="<?php echo $pdfname; ?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
//