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("[email protected]", "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!'; } Link to comment https://forums.phpfreaks.com/topic/110080-solved-sequential-file-naming/ 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. Link to comment https://forums.phpfreaks.com/topic/110080-solved-sequential-file-naming/#findComment-564895 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. Link to comment https://forums.phpfreaks.com/topic/110080-solved-sequential-file-naming/#findComment-564905 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("[email protected]", "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!! Link to comment https://forums.phpfreaks.com/topic/110080-solved-sequential-file-naming/#findComment-564914 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. Link to comment https://forums.phpfreaks.com/topic/110080-solved-sequential-file-naming/#findComment-564934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.