When I run the file on my localhost
it works, but when i upload it to my server using winSCP
, I'm getting this error
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
Is it because the server couldn't find the file path or I wrote it wrong?
I tried giving permission on folder src but it said cannot change properties of file src. I am a beginner in this field. I tried search the solution on google regarding this error but I couldn't find anything.
In case you want to give mPDF another try:
it seems you are not providing the proper configuration to mPDF but we can't tell for sure as that part of your code (line 88 of your print-form.php
) is missing. Taken from my last code using 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();
}
Line 17 in Cache.php
is part of the Cache constructor and throws an error in case the temporary directory is either not writable or not a directory:
// taken from method "createBasePath($basePath)"
if (!is_writable($basePath) || !is_dir($basePath)) {
return false;
}
To test if you see the error due to insufficient file permissions or a non-existing directory, upload a file with this content to your server and navigate to it with your preferred browser:
<?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 />';
You are on a Windows server so you will need to add the right user to the "tmp" folder under "Properties"->"Security", additionally check if the folder has the Attribute "Read-only" unticked.
Additional advice:
Please post relevant code in your future question (like the relevant portions of your print-form.php
) as this reduces the risks of having to guess what might be the cause.