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("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!';

}

Link to comment
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.