PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

Strange warnings

Open LaySoft opened this issue 3 years ago • 3 comments

I open a xlsx file:

use PhpOffice\PhpSpreadsheet\IOFactory;
$spreadsheet = IOFactory::load('temp.xlsx');

The open success, but the following warnings occured:

Warning: file_exists(): open_basedir restriction in effect. File(/xl/styles.xml) is not within the allowed path(s): (/store/virtweb/:/tmp/:/usr/share/php/:/store/virtweb/_phpsessions/:/store/virtweb/_phptmp/) in /store/virtweb/admin.notebook-alkatresz.hu/www/API/PhpOffice/PhpSpreadsheet/Shared/File.php on line 88
Warning: file_exists(): open_basedir restriction in effect. File(/xl/workbook.xml) is not within the allowed path(s): (/store/virtweb/:/tmp/:/usr/share/php/:/store/virtweb/_phpsessions/:/store/virtweb/_phptmp/) in /store/virtweb/admin.notebook-alkatresz.hu/www/API/PhpOffice/PhpSpreadsheet/Shared/File.php on line 88
Warning: file_exists(): open_basedir restriction in effect. File(/xl/workbook.xml) is not within the allowed path(s): (/store/virtweb/:/tmp/:/usr/share/php/:/store/virtweb/_phpsessions/:/store/virtweb/_phptmp/) in /store/virtweb/admin.notebook-alkatresz.hu/www/API/PhpOffice/PhpSpreadsheet/Shared/File.php on line 88
Warning: file_exists(): open_basedir restriction in effect. File(/xl/worksheets/sheet1.xml) is not within the allowed path(s): (/store/virtweb/:/tmp/:/usr/share/php/:/store/virtweb/_phpsessions/:/store/virtweb/_phptmp/) in /store/virtweb/admin.notebook-alkatresz.hu/www/API/PhpOffice/PhpSpreadsheet/Shared/File.php on line 88
Warning: file_exists(): open_basedir restriction in effect. File(/xl/worksheets/sheet1.xml) is not within the allowed path(s): (/store/virtweb/:/tmp/:/usr/share/php/:/store/virtweb/_phpsessions/:/store/virtweb/_phptmp/) in /store/virtweb/admin.notebook-alkatresz.hu/www/API/PhpOffice/PhpSpreadsheet/Shared/File.php on line 88

Why the PhpSpreadsheet/Shared/File.php script tries to open misterious files?

LaySoft avatar Feb 08 '22 13:02 LaySoft

Those "mysterious files" are part of the xlsx file that you're trying to load: an xlsx file is actually a zip archive containing a lot of individual xml files like /xl/styles.xml, /xl/workbook.xm and /xl/worksheets/sheet1.xml. To read the xlsx, we have to read the contents of the individual xml files that exist in that xlsx.

It would seem that you have an open_basedir restriction enabled in your php.ini, and it's being rather over-zealous in reporting. open_basedir should be warning about restricted access to the files on your system disk; not within the zipstream.

MarkBaker avatar Feb 08 '22 16:02 MarkBaker

Those "mysterious files" are part of the xlsx file that you're trying to load: an xlsx file is actually a zip archive containing a lot of individual xml files like /xl/styles.xml, /xl/workbook.xm and /xl/worksheets/sheet1.xml. To read the xlsx, we have to read the contents of the individual xml files that exist in that xlsx.

It would seem that you have an open_basedir restriction enabled in your php.ini, and it's being rather over-zealous in reporting. open_basedir should be warning about restricted access to the files on your system disk; not within the zipstream.

At the line of the problem it call file_exists to check file existance. So it check file system disk instead of checking from inside zipstream. PhpOffice/PhpSpreadsheet/Shared/File.php on line 88

Do we need to check file existance on system disk in some scenario ?

kentreez avatar May 01 '22 11:05 kentreez

The use of file_exists in PhpOffice/PhpSpreadsheet/Shared/File.php on line 88 throws a warning, which seems pretty unnecessary for checking for definition files within the xlsx zip.

How about just suppressing the error?

if (@file_exists($filename)) { $returnValue = realpath($filename) ?: ''; }

hessodreamy avatar Apr 21 '23 12:04 hessodreamy