上载在服务器中时,MPDF临时文件目录并不可写



当我在localhost上运行文件时,它可以工作,但是当我使用winSCP上传到服务器时,我会遇到此错误

PHP Fatal error: Uncaught MpdfMpdfException: Temporary files directory "E:Inetpubvhostsgsm.org.myhttpdocsprint/custom/temp/dir/path" is not writable in E:Inetpubvhostsgsm.org.myhttpdocsprintvendormpdfmpdfsrcCache.php:17
Stack trace:
#1 E:Inetpubvhostsgsm.org.myhttpdocsprintvendormpdfmpdfsrcMpdf.php(1054): MpdfServiceFactory->getServices(Object(MpdfMpdf), Object(PsrLogNullLogger), Array, 0, Object(MpdfLanguageLanguageToFont), Object(MpdfLanguageScriptToLanguage), NULL, NULL, NULL, NULL)
#2 E:Inetpubvhostsgsm.org.myhttpdocsprintprint-form.php(88): MpdfMpdf->__construct(Array)
#3 {main} thrown in E:Inetpubvhostsgsm.org.myhttpdocsprintvendormpdfmpdfsrcCache.php on line 17

是因为服务器找不到文件路径还是我写了错误?

我尝试在文件夹SRC上授予权限,但它说无法更改文件SRC的属性。我是这个领域的初学者。我尝试在Google上搜索有关此错误的解决方案,但找不到任何东西。

如果您想给MPDF再尝试:

似乎您没有为MPDF提供适当的配置,但是我们无法确定,因为丢失了代码的那一部分(print-form.php的第88行)。使用MPDF取自我的最后一个代码:

try {
  $mpdf = new MpdfMpdf([
    'tempDir' => __DIR__ . '/../tmp', // uses the current directory's parent "tmp" subfolder
    'setAutoTopMargin' => 'stretch',
    'setAutoBottomMargin' => 'stretch'
  ]);
} catch (MpdfMpdfException $e) {
    print "Creating an mPDF object failed with" . $e->getMessage();
}

Cache.php中的第17行是缓存构造函数的一部分,并在临时目录不写或不是目录的情况下引发错误:

// 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 Server上,因此您需要将正确的用户添加到" properties" ->" Security"下的" TMP"文件夹中,此外,请检查该文件夹是否具有未键入的属性"无读"。

其他建议:

请在未来的问题中发布相关代码(例如print-form.php的相关部分),因为这降低了必须猜测可能是原因的风险。

,而不是在初始化PDF对象时每次这样做。您也可以在Main Config File

中设置

路径:供应商/mpdf/mpdf/src/config在下面变量(tempdir)中的更改路径:

'tempdir'=&gt;'/var/log/temp',

最新更新