laravel mpdf 更改临时路径(作曲家包)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27531935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:34:19  来源:igfitidea点击:

mpdf change temp path (composer package)

phplaravelpermissionsmpdf

提问by Gravy

I have installed mpdf/mpdfvia composer.

我已经mpdf/mpdf通过作曲家安装了。

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:

根据 mpdf 文档,我需要定义存储文件夹的路径:

// 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

我使用 Laravel 作为框架 - 而 mpdf 不会使用我指定的临时文件夹

回答by jon__o

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.

我知道这是一个老问题,但我遇到了同样的问题。就像您最初建议的那样,您可以在加载 mPDF 库之前定义临时路径,但也需要定义字体数据路径。

I added this to the top of my /bootstrap/autoload.php file:

我将此添加到我的 /bootstrap/autoload.php 文件的顶部:

define("_MPDF_TEMP_PATH", __DIR__.'/../storage/framework/pdf/');
define("_MPDF_TTFONTDATAPATH", __DIR__.'/../storage/framework/pdf/fonts/');

Additionally, I had to create the /pdfand /pdf/fontsdirectories manually.

此外,我必须手动创建/pdf/pdf/fonts目录。

There is probably a cleaner way to do this, but this is a quick fix.

可能有一种更简洁的方法可以做到这一点,但这是一个快速解决方案。

回答by Aziz

Have you set permissions for the following folders?

您是否为以下文件夹设置了权限?

  • /ttfontdata/
  • /tmp/
  • /graph_cache/
  • /tt字体数据/
  • /tmp/
  • /graph_cache/

Here's a guide of how to install: http://mpdf1.com/manual/index.php?tid=509

这是如何安装的指南:http: //mpdf1.com/manual/index.php?tid=509