In my script, I have the following lines:
$test = @imagecreatefrompng($name);
if ($test) { ... }
I am certain that $name
represents an existing file on the disk, but I must handle cases where that file is not a valid PNG file (either because of a transfer error or because of a malicious user). I wish to handle such cases by not doing anything at all.
However, given the above code, my PHP interpreter stops on the first line with the following error message:
imagecreatefrompng() [function.imagecreatefrompng]: 'foobar.png' is not a valid PNG file
Shouldn't '@
' have suppressed this error message and had the function return false
as described in the documentation? How can I tell PHP that I know an error might happen and not interrupt the execution?