hoopplaya4 Posted June 13, 2008 Share Posted June 13, 2008 Hey All, I'm using tcPDF to take the values of a form, create a PDF, (test.pdf) and then store it on the server. Right now I have it set up to overwrite the same PDF everytime, What can I add into my code to make it create a new file everytime, for example: test0001.pdf, test0002.pdf, test0003.pdf, etc.? Here's a snippet of code I'm using: $filename = "test.pdf"; $pdf->Output($filename, "F"); $mail = new PHPMailer(); $mail->MsgHTML($body); $mail->AddAddress("myemail@gmail.com", "My Name"); if(!$mail->AddAttachment($filename)) { echo "There was a problem attaching the pdf."; echo $mailer->ErrorInfo; } if(!$mail->Send()) { echo 'Failed to send mail'; } else { echo 'Mail sent!'; } Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 13, 2008 Share Posted June 13, 2008 do you have access to a database? If so you could simpyl make it get the number from a db and increase it each time by 1. Alternatively if you are simply after a random number you could use the date function to grab the current time in seconds and use that. Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted June 13, 2008 Author Share Posted June 13, 2008 Thanks for the quick reply. Could you explain or provide a link on how to use the date function? Even a small example would help. Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted June 13, 2008 Author Share Posted June 13, 2008 OK: I figured out the date code, but more specifically, how would I include the ".pdf" portion. I'm not sure if my syntax is correct. Here's what I have: $filename = date("H.i.s"); $pdf->Output($filename, "F"); $mail = new PHPMailer(); $mail->MsgHTML($body); $mail->AddAddress("myemail@gmail.com", "My Name"); if(!$mail->AddAttachment($filename)) { echo "There was a problem attaching the pdf."; echo $mailer->ErrorInfo; } if(!$mail->Send()) { echo 'Failed to send mail'; } else { echo 'Mail sent!'; } Where would I add the .pdf? And how? Thanks!! Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted June 13, 2008 Author Share Posted June 13, 2008 Never mind! I figured it out. I just used: $filename = date('H.i.s\.\p\d\f'); And it worked great. Thanks for the recommendation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.