3

I'm trying to save a pdf file using the html2pdf PHP class. The code is this:

$this->html2pdf->Output('directory/file_name.'.pdf', 'F');

But I have alway this error TCPDF ERROR: Unable to create output file

the folder 'folder' (the name is an example, obviusly), exist and has the right permissions!

I tryed to omit the folder name, but this error appear anyway...

Anyone can help me?

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
Daniele
  • 538
  • 1
  • 5
  • 17
  • Is that the *exact* line as it appears in your php? It seems to me your string concatenation is wrong (see http://stackoverflow.com/questions/12304553/tcpdf-save-file-to-folder). – Jongware Dec 24 '13 at 01:38

5 Answers5

4

thats because your folder dont have proper permissions.change your directory permissions. in linux you will do this like mentioned below.

 chmod -R 0777 /yourdirectory
R R
  • 2,999
  • 2
  • 24
  • 42
3

In the 'include/tcpdf_static.php' file about 2435 line in the static function 'fopenLocal' if I delete the complete 'if statement'... works fine.

public static function fopenLocal($filename, $mode) {
  /*if (strpos($filename, '://') === false) {

    $filename = 'file://'.$filename;
  } elseif (strpos($filename, 'file://') !== 0) {
    return false;
  }*/
  return fopen($filename, $mode);
}
durron597
  • 31,968
  • 17
  • 99
  • 158
Atul Baraiya
  • 141
  • 1
  • 2
0

If you already tried al these things, try

sudo setenforce 0

Worked for me!

Jannes

Jannes
  • 19
  • 5
0
$pdf->Output(APP . 'webroot' . DS . 'files' . DS . 'pdf' . DS . 'filename.pdf', 'F');

Try this ...

BDL
  • 21,052
  • 22
  • 49
  • 55
  • Although this code might (or might not) solve the problem, a good answer always requires an explanation on why it works and how it solves the problem. Also note, that it is unclear what `$pdf` is. – BDL Nov 28 '17 at 10:40
0

make sure that your file('directory/file_name.'.pdf') is not open anywhere when you run script. if it's open somewhere else then TCPDF can't open it.

Divyesh Jesadiya
  • 1,105
  • 4
  • 30
  • 68