TCPDF ERROR: Unable to create output file
Solution 1:
Try putting ob_clean(); right above $pdf->Output('output.pdf', 'F');
ob_clean();
// save file
$pdf->Output('output.pdf', 'F');
if that dont work. Than you need to set a path like this:
$pdf->Output('yourpath/output.pdf', 'F');
if you dont know the absolute path try this:
$pdf->Output($_SERVER['DOCUMENT_ROOT'] . 'output.pdf', 'F');
Solution 2:
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);
}
Solution 3:
You have to put the full path instead of relative one, example of usage with__DIR__:
$pdf->Output(__DIR__."/../invoices/invoice_".date('d-M-Y').".pdf", 'F');
Solution 4:
this is a tip for laravel programmers who using tcpdf if you want to save pdf to your public directory, just use this:
PDF::Output(public_path('/uploads/pdf/hello_world.pdf'),'F');
Solution 5:
the issue is caused by file's path. I get this fixed by changing $pdf->Output('output.pdf', 'F');
to absolute path $pdf->Output('/var/www/yourdomain/output.pdf', 'F');