Thanks for this amazing piece of code!
It helped me a lot with my current project - with a small modification:
$info = unpack('a8sig/Nchunksize/A4chunktype/Nwidth/Nheight/Cbit-depth/'.
'Ccolor/Ccompression/Cfilter/Cinterface',
file_get_contents($file,0,null,0,29))
;
With "A8sig" the last "0A" is droped and the PNG signature comparison fails.
With "a8sig" it worked for me.
Just to be mentioned...
(PHP 5.5.9, Win7x64)