问题
I have installed mpdf/mpdf
via composer.
All works perfectly in development environment, however in production / staging, I get a permissions error.
file_put_contents(\/.../ttfontdata\/dejavusanscondensed.GSUBGPOStables.dat): failed to open stream: Permission denied' in .../shared\/vendor\/mpdf\/mpdf\/classes\/ttfontsuni.php:999\nStack trace:\n#0 [internal function]: Illuminate\\Exception\\Handler->handleError(2, 'file_put_conten...', '...', 999, Array)\n#1
As per mpdf documentation, I need to define the path for my storage folder:
// Tried this at top of index.php before require bootstrap/autoload.php
define("_MPDF_TEMP_PATH", dirname(__FILE__) . '/../app/storage/mpdf/');
// Tried this just before creating a new mpdf
define("_MPDF_TEMP_PATH", storage_path() . '/mpdf/');
I am using Laravel as a framework - and mpdf just will not use my specified temp folder
回答1:
I know this is an old question, but I had the same issue. Just like you originally suggested, you can define the temp path prior to loading the mPDF library, but the font data path also needs to be defined.
I added this to the top of my /bootstrap/autoload.php file:
define("_MPDF_TEMP_PATH", __DIR__.'/../storage/framework/pdf/');
define("_MPDF_TTFONTDATAPATH", __DIR__.'/../storage/framework/pdf/fonts/');
Additionally, I had to create the /pdf
and /pdf/fonts
directories manually.
There is probably a cleaner way to do this, but this is a quick fix.
回答2:
Have you set permissions for the following folders?
- /ttfontdata/
- /tmp/
- /graph_cache/
Here's a guide of how to install: http://mpdf1.com/manual/index.php?tid=509
来源:https://stackoverflow.com/questions/27531935/mpdf-change-temp-path-composer-package