mpdf - mpdf临时文件目录在服务器上传时不可写
问题描述
当我在我的文件上运行localhost
它时它可以工作,但是当我使用它将它上传到我的服务器时winSCP
,我收到了这个错误
PHP Fatal error: Uncaught Mpdf\MpdfException: Temporary files directory "E:\Inetpub\vhosts\gsm.org.my\httpdocs\print/custom/temp/dir/path" is not writable in E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\vendor\mpdf\mpdf\src\Cache.php:17
Stack trace:
#1 E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\vendor\mpdf\mpdf\src\Mpdf.php(1054): Mpdf\ServiceFactory->getServices(Object(Mpdf\Mpdf), Object(Psr\Log\NullLogger), Array, 0, Object(Mpdf\Language\LanguageToFont), Object(Mpdf\Language\ScriptToLanguage), NULL, NULL, NULL, NULL)
#2 E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\print-form.php(88): Mpdf\Mpdf->__construct(Array)
#3 {main} thrown in E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\vendor\mpdf\mpdf\src\Cache.php on line 17
是因为服务器找不到文件路径还是我写错了?
我尝试授予文件夹 src 的权限,但它说不能更改文件 src 的属性。我是这个领域的初学者。我尝试在谷歌上搜索有关此错误的解决方案,但我找不到任何东西。
解决方案
如果您想再试一次 mPDF:
似乎您没有为 mPDF 提供正确的配置,但我们无法确定,因为您的代码的那部分(您的第 88 行print-form.php
)丢失了。取自我使用 mPDF 的上一个代码:
try {
$mpdf = new \Mpdf\Mpdf([
'tempDir' => __DIR__ . '/../tmp', // uses the current directory's parent "tmp" subfolder
'setAutoTopMargin' => 'stretch',
'setAutoBottomMargin' => 'stretch'
]);
} catch (\Mpdf\MpdfException $e) {
print "Creating an mPDF object failed with" . $e->getMessage();
}
第 17 行Cache.php
是 Cache 构造函数的一部分,如果临时目录不可写或不是目录,则会引发错误:
// taken from method "createBasePath($basePath)"
if (!is_writable($basePath) || !is_dir($basePath)) {
return false;
}
要测试您是否看到由于文件权限不足或不存在的目录而导致的错误,请将包含此内容的文件上传到您的服务器并使用您首选的浏览器导航到该文件:
<?php
$pathToCheck= "E:\\Inetpub\\vhosts\\gsm.org.my\\httpdocs\\print//custom//temp//dir//path";
print 'Folder exists: '.(is_dir($pathToCheck) ? 'yes' : 'no').'<br />';
print 'Folder is writable: '.(is_writable($pathToCheck) ? 'yes' : 'no').'<br />';
您在 Windows 服务器上,因此您需要将正确的用户添加到“属性”->“安全”下的“tmp”文件夹,另外检查该文件夹是否未勾选“只读”属性。
附加建议:
请在您未来的问题中发布相关代码(如您的相关部分print-form.php
),因为这样可以减少猜测可能是什么原因的风险。
推荐阅读
- azure - 使用分页列出 Azure Blob
- c - C 语言中是否有命令读取行,但不包括所有换行符?
- ruby-on-rails - 如何使用 login def 验证登录表单
- javascript - 如何在单个 JavaScript 文件中使用仅 ESM 的 npm 包和普通的 npm 包?
- android - 如何正确显示视图模型中的数据?
- javascript - JavaScript 电子邮件模式为无效格式返回 true
- ios - Swift:如何以编程方式布局弹出页面控制器的子视图?
- python - 需要帮助解决问题 ''AttributeError: 'function' object has no attribute 'summary'''
- django - 无法在已部署的 Django 应用程序(Docker、gunicorn、whitenoise、Heroku)中提供静态文件
- android - Firestore - 在kotlin的对象数组中按项目获取文档