views:

22

answers:

2

I have a simple problem but somehow I cannot solve it. I want to create a pdf file and therefore I tried the example provided by Zend (here). When I run the code I get the following error: "PDF error: Can not open 'example.pdf' file for writing". I think the problem are the permissions. But I don't know which file should get the write permission. Instead of just providing every file the permission I wanted to ask if anyone knows what exactly I need to do.

+1  A: 

Change the path of the saved file to something like this and make the directory writable.

$pdf->save('path/to/example.pdf');

If you want to be able to overwrite the file use the following:

$pdf->save('path/to/example.pdf', TRUE);
Skelton
A: 

you should add something like this to be able to cleanly handle the case of missing write permissions

$path = 'path/to/example.pdf';
$folder = dirname($fileToWrite);
if (!is_dir($folder) ||
    !is_writeable($folder) ||
    (file_exists($path) && !is_writeable($path)) {

    throw new Exception('The server admin does not allow you to write the file. ask him to give you the required permissions to write "'. $path . '"');
}
zolex