Question

I am trying to populate a pdf report with data from my mysql database. It works fine on my local machine but when I upload it to www.000webhost.com, the pdf document is not generated.

I know the document writes a temp file to my folder every time I click print report.Can anyone tell me why it doesn't work on the hosting provider and how I can fix this issue. I am under the impression that it is a security issue.

Do I have to write a temp file. Why couldn't I have used the $fdf variable to populate the report instead of the temporary file?

$fdf_fn= tempnam( '.', 'fdf' );
$fp= fopen( $fdf_fn, 'w' );
if( $fp ) {
    fwrite( $fp, $fdf );
    fclose( $fp );

//attachment for view
header(   'Content-type: application/pdf' );
header(   'Content-disposition: inline; filename=TEST.pdf');

passthru(   "pdftk ./../../reports/TEST.pdf fill_form ". $fdf_fn.' output - flatten' );

unlink( $fdf_fn ); // delete temp file
Was it helpful?

Solution

Can anyone tell me why it doesn't work on the hosting provider and how I can fix this issue. I am under the impression that it is a security issue.

My guess is you simply don't have write permission in the required directory.

You create your temporary file in the current working directory (.). Depending on your hosting provider and the HTTP server configuration, the current working directory is not necessary what you think nor writable. Especially since your program will probably run with the www or nobody identity.

I assume you have to create and then adjust the permissions on your "temporary" directory -- or use a "world writable" location such as /tmp.

Finally, you have a relative path that move "upward" in your program: ./../../reports/TEST.pdf fill_form There is little chances for this to be valid on your hosting...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top