Divyam Jain
Divyam Jain

Reputation: 29

Failed to open stream: Permission denied using fpdf

While using fpdf class in ubuntu linux apache server, I got above warning. Then there is an fatal error:

Uncaught exception 'Exception' with message 'FPDF error: Unable to create output file: result.pdf' in /opt/lampp/htdocs/website/fpdf.php:271 Stack trace: #0 /opt/lampp/htdocs/website/fpdf.php(1022): FPDF->Error('Unable to creat...') #1 /opt/lampp/htdocs/website/generate.php(185): FPDF->Output('result.pdf', 'F') #2 {main} thrown in /opt/lampp/htdocs/website/fpdf.php on line 271

Upvotes: 1

Views: 7447

Answers (3)

Divyesh Jesadiya
Divyesh Jesadiya

Reputation: 957

make sure that file result.pdf is not open anywhere when you run script. if it's open somewhere else then TCPDF can't open it.

Upvotes: 0

Divyam Jain
Divyam Jain

Reputation: 29

I solved the problem by making doing the following in my PHP file:

$pdf->Output('result.pdf', 'D');

$pdf is my object of the FPDF class. I set the parameter as 'D', which forces a file download with the provided name.

Upvotes: 0

Jason
Jason

Reputation: 18

Sounds like a permissions issue. Whatever user the webserver runs under must have permission to create/modify the file. This is very likely not the same user you login as. If you have access, su as the webserver user (eg. sudo su - apache), then try to create the file manually. The shell command "touch" will do the trick. That will tell you if the webserver has access.

Upvotes: 0

Related Questions