I've got an older piece of code that attempts to load an image file. Since it doesn't know what type it is, the code tries them all:
$res = @imagecreatefromjpeg($sourceName);
if ( $res === false)
$res = @imagecreatefromgif($sourceName);
if ( $res === false)
$res = @imagecreatefrompng($sourceName);
if ( $res === false) {
$err[] = 'Cannot load file as JPEG, GIF or PNG!';
This used to work perfectly for a long time, but after a recent server migration it stopped working when using a PNG file (JPEG files work fine). Investigation revealed that the very first line produces a fatal error:
Fatal error: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts with 0x89 0x50
Since the line has the error-suppression operator, the script simply stopped executing and returned HTTP 200 with an empty response.
What I don't understand is... wha... how... why... since when... huh?
Even the official documentation says that these functions return FALSE
when unable to load a file, and the construct with the @
operator is shown there too. I can find nothing on the web which would say that "not a JPEG file" is a fatal error. Everywhere it's mentioned, it's a warning as it always has been. Why am I getting a fatal error now?
My PHP is 5.6.30, GD is there with everything.