17

I'm using dompdf to create and mail a PDF file to my mail and at the same time, save a .txt version on the server. Saving the file is working as it should, but im having a bit of trouble getting it to save it with a unique name. In this case i wanted something like date-time.txt ( 06-09-2012_11:43.txt )

or even better, if it could have the name from the text field "refnr" as the name.

<label for="refnr"><b>Referensnummer:</b></label>
<input type="text" name="refnr" id="refnr" class="input" />

The code looks like this:

$html = '/html.php';
$filename = $dir.'/Admin/files/"date here".txt';
$dompdf = new DOMPDF(); 
$dompdf->load_html($html); 
$dompdf->set_paper('a4', 'portrait');
$dompdf->render(); 
file_put_contents($filename, $dompdf->output()); 

I tried to play around with $name='myfile_'.date('m-d-Y_hia)'; but couldn't make that work, it just gave an error on that line every time. So now im here to seek the guidance from you smart people :)

denully
  • 215
  • 1
  • 2
  • 8
  • "It just gave an error" -> which? – Gordon Sep 06 '12 at 10:31
  • it just said Parse error: syntax error, unexpected T_STRING in /var/www/virtual/denully.dk/try-it.dk/htdocs/Ikea/form.php on line 34 :) not that helpful i think hehe, line 34 was the $filename = $dir.'/Admin/files/"date here".txt'; line – denully Sep 06 '12 at 10:46

1 Answers1

45

You put the ) before you closed the string format code:

$name='myfile_'.date('m-d-Y_hia');

Should work fine.

As Jan1337z points out, you probably want a suffix on the file:

$name='myfile_'.date('m-d-Y_hia').'.txt';

Not having a suffix should't stop the file being created - but having it will probably help make it easily usable.

Fluffeh
  • 33,228
  • 16
  • 67
  • 80