-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
This is:
less
- a bug report
- a feature request
- not a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
What is the expected behavior?
Running PhpSpreadsheet version 1.29.0 on PHP 7.4 without issues, as it is supposed to support this PHP version.
What is the current behavior?
An error occurs due to the usage of str_starts_with, which is a PHP 8.0 function, in the Drawing.php file. This function is not compatible with PHP 7.4.
What are the steps to reproduce?
$spreadsheet = IOFactory::load($_FILES['fileSEPA']['tmp_name']);
Error location
The error is located in the vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Drawing.php file, specifically in the isImage method:
private function isImage(string $path): bool
{
$mime = (string) @mime_content_type($path);
$retVal = false;
if (str_starts_with($mime, 'image/')) { // This line causes the error
$retVal = true;
} elseif ($mime === 'application/octet-stream') {
$extension = pathinfo($path, PATHINFO_EXTENSION);
$retVal = in_array($extension, ['bin', 'emf'], true);
}
return $retVal;
}
What features do you think are causing the issue
Reader
Writer
Styles
Data Validations
Formula Calculations
Charts
AutoFilter
Form Elements
Drawing (specifically)
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
N/A
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet: 1.29.0
PHP: 7.4
Suggested Solution
Replace the str_starts_with function in Drawing.php with an alternative compatible with PHP 7.4, such as strpos($mime, 'image/') === 0.