Forum How do I...?

how to fwrite results to a file on the server using php

no1uknow
Trying to fwrite the pdf results from PrinceXML to the server (in a new pdf file) instead of exporting via headers to acrobat. The below code displays the results on the browser.

require_once("../library/Prince/prince.php");
$princeSettings = $this->getInvokeArg('bootstrap') >getOption('prince');
$prince = new Prince($princeSettings['path']);
$prince->setHTML(true);
$result = $prince->convert_string_to_passthru($this->htmlView);

$fp = fopen("./files/reports/report.pdf", "w");
fwrite($fp, $result);
fclose($fp);
mikeday
You can call convert_string_to_file instead, then you don't need to use fwrite.

If this doesn't work, it could be that PHP does not have write permissions to the specified directory. You could try writing to /tmp to check that, or check the error/warning messages returned from Prince in the msgs array parameter of convert_string_to_file.

Edited by mikeday