I use mpdf:
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'setAutoTopMargin' => 'stretch',
'setAutoBottomMargin' => 'stretch',
'tempDir' => TMP
]);
On hosting, after calling the script, I get an error:
Warning (2): is_file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/data/web/virtuals/102030/virtual) [ROOT/vendor/mpdf/mpdf/src/Mpdf.php, line 11353]
Please advise how to solve this problem, I have no error on the local server.
What is your TMP
setting? Guessing that this is probably something like /tmp
and your host is blocking that.
TMP is a variable - constant from the PHP CAKE environment, if I remove it then the error is the same.
Hosting is shared with other hosting companies, this could be a problem. The question is how to solve it so that it does not return errors.
I know it’s a constant. I’m asking what the value of that constant is.
The value is: /data/web/virtuals/102030/virtual - if I remove (tempDir) option it then the error is the same.
Have you looked at vendor/mpdf/mpdf/src/Mpdf.php, line 11353
, where the error message indicates the problem is happening?
On line is:
} elseif ((strpos($path, ":/") === false || strpos($path, ":/") > 10) && !is_file($path)) { // It is a local link
and above:
// When parsing CSS need to pass temporary basepath - so links are relative to current stylesheet
if (!$basepath) {
$basepath = $this->basepath;
}
// Fix path value
$path = str_replace("\\", '/', $path); // If on Windows
// mPDF 5.7.2
if (substr($path, 0, 2) === '//') {
$scheme = parse_url($basepath, PHP_URL_SCHEME);
$scheme = $scheme ?: 'http';
$path = $scheme . ':' . $path;
}
$path = preg_replace('|^./|', '', $path); // Inadvertently corrects "./path/etc" and "//www.domain.com/etc"