How can I generate a dynamic file name for my PDF File with dompdf?
I am using dompdf which seems to be going really well.
I get my generated pdf file as an email attachment. I wanted to know how to append a unique number to the file name so that every users that receives the pdf does not have the same exact file name.
I currently get name the file and get whatever I name have assigned it successfully, such as myfile.pdf.
As a test, I can also get a random number appended to the 开发者_开发技巧filename like this:
$message = Swift_Message::newInstance()
->setSubject('My Subject Text') // Message subject
->setTo(array('me@mydomain.com' => 'MyName')) // Array of people to send to
->setFrom(array('no-reply@mydomain.com' => 'SenderName')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->attach(Swift_Attachment::newInstance($pdf_content, 'myfile'.rand(10,1000).'.pdf', 'application/pdf')); // Attach the generated PDF from earlier
That works great for sending a pdf with the filename and random number.
But how can I do this with something that makes more sense?
Like starting with a specific number and auto-incrementing for every file that gets submitted?
Or using numbers based on (or from) the SESSION?
What is the best practice that would make sense?
I would like each file name to be myfile_UNIQUENUMBER.pdf (I think some type of auto-increment or SESSION number would be best)
Thoughts?
You may use the date as unique number when use it with d/m/year
AND TIME with a name you choose so every filename will have different number..try this code :
$tym = date('m-d-Y : hi a');
$filename = ' APPLICATION '.$tym; // YOU CAN CHOOSE YOUR FILE NAME
$message = Swift_Message::newInstance()
->attach(Swift_Attachment::newInstance($pdf_content, $_POST["username"] . $filename. ".pdf", 'application/pdf')); //
精彩评论