Jump to content

[SOLVED] Sequential File Naming


hoopplaya4

Recommended Posts

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

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.

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!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.