在服务器上传时,mpdf临时文件目录不可写

问题描述 投票:0回答:1

当我在我的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
1个回答
0
投票

如果你想给另一个mPDF尝试:

看来你没有为mPDF提供正确的配置,但我们无法确定你的代码中的那部分(你的print-form.php的第88行)是否缺失。取自我上一次使用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();
}

Cache.php中的第17行是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的相关部分),因为这样可以降低猜测可能是什么原因的风险。

© www.soinside.com 2019 - 2024. All rights reserved.