0

I've these days been trying to automatically save a PDF file just after creating it, using TCPDF. But I always get prompted for a save destination, and I have to click the "save" button in order to save the file in a certain location. I want all of this to be automatic:

  1. Set the distination folder of the file.
  2. Download the file.

here is my code:

$pdf = new TCPDF('P','mm','A4');
$pdf->AddPage();
$pdf->Output("C:\Users\f377185\Desktop", 'I');   
$pdf->Output("C:\Users\f377185\Desktop", 'F'); 

Can you help me ?

Martin
  • 2,326
  • 1
  • 12
  • 22
  • The destination folder is defined in the client's browser settings, not in the output file. – Alfabravo Sep 04 '18 at 08:44
  • I don't think you have access to user destination folders. That would essentially be a huge risk for the user, so I believe that is blocked, and why you have to prompt the user for a save destination. The only way you could set an automated destination would be if you saved it to a server directory, and/or use the browsers standard set download folder by browser settings. – Martin Sep 04 '18 at 08:48
  • Try saving it to a folder under your DocumentRoot. If that works, the problem is probably that you web server is not allowed to access the folder you are trying to save the file to, and quite rightly as that is your userid's desktop folder and even if you are trying to save it there, that wont work when you move the site to a host that is not on your PC and probably does not run Windows anyway – RiggsFolly Sep 04 '18 at 09:00
  • thank you all for your replies, actually i'm trying to save the pdf file in my pc just for testing purposes but then i will run my app on a server. what should i do ? – Oussama Fathallah Sep 04 '18 at 09:08
  • 1
    If you are successfully creating the pdf, then `$pdf->Output("/file/path", 'F');` should work. It could simply be, as I said, because you don't have access to user directories, but have to use a server directory, else it will prompt the user for a save destination. – Martin Sep 04 '18 at 09:42

0 Answers0