I have to write a custom module extension, that saves entityform submission after hitting submit button to a PDF file in the private://pdf/<file_name>
uri.
At first step it generates the PDF file to a temp directory via TCPDF and then I try to use file_save_data
to save it to private directory and upload the file data to the db.
When I upload the file to the public directory, there are no problems, but when I set the uri to private://<pathname/filename>
it sends me an error message:
"The data could not be saved, because the destination is invalid. More information is available in the system log".
In the system log:
"The data could not be saved because the destination private://pdf/employee_aontest_richie_2014-06-03_00_00_00_59.pdf is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper."
The code, that should save the whole thing is this:
$title = $node->title; // TCPDF doesn't let you have spaces or colons in your file name
$title_exploded = explode(' ', $title);
$title_imploded = implode('_', $title_exploded);
$imp_exploded = explode(':', $title_imploded);
$imp_exp_imploded = implode('_', $imp_exploded);
$real_title = drupal_strtolower($imp_exp_imploded);
//end of title generation
$save_path = 'private://pdf/'.$real_title.'.pdf';
$handle = fopen($full_path_tcpdf_output, 'r');
$file = file_save_data($handle, $save_path);
fclose($handle);
unlink($full_path_tcpdf_output);
I think the file saving procedure should work this way as it works if I save to public.
I appreciate any further advices.