Php 5.3 and getgetimagesize fails to get swf dimensions


Have this odd issue where if I set a domain to run as PHP 5.3.5 (fast cgi) getimagesize fails to return any results for a swf file.

Changing to PHP 5.2 fixes any issues. Oddly, running 5.3.3 locally works fine as well.

I am providing getimagesize with paths, rather than URLS.

Has anyone else come across this?

That’s really strange - the documentation for getimagesize ( doesn’t say SWF is a supported file type. I wouldn’t have expected it to be, either, as SWF files aren’t really images (you can’t reference them from an tag, for instance).

It’s possible something changed about the image library, but I’m unlikely to look into it much unless there’s something more serious than this that changed.

Yeah, swfs (swc) are definitely supported, but maybe not anymore in PHP 5.3.5. I’ve not noticed any changes in the release notes to that effect though. I’ll poke around and see if I can find anything.

I recently sent in a support request about this. The getimagesize definitely supports SWF however it requires a static zlib to link against, having the zlib extension doesn’t seem to cut it (as Dreamhost’s PHP 5.3 install has Zlib extension 1.1 by default I think), this is because the vast majority of SWF’s are compressed.

If you enable all error reporting when this function is called (which phpBB uses heavily by the way), then you get the following error:

It’s definitely a change from 5.2, however nothing default in 5.3 accounts for it, so it appears to be something screwy with Dreamhost’s 5.3 setup, as a default local install of 5.3 seems to be fine, even the zlib extension isn’t enabled by default; this being because getimagesize doesn’t require the zlib extension to actually be enabled.

I was hoping there’d be a way to work around it with PHP.ini directives, as I wanted to use PHP 5.3 due the much simpler phprc setup method for customising settings, but it’s a non-starter until this is fixed :frowning:

I just wanted to add that after talking to support it seems that this issue may (hopefully) be fixed for PHP 5.4 when it’s ready to be deployed on virtual hosts.

In the mean-time there is a workaround for the issue, as gzuncompress() still works, so it’s possible to get the width and height data out of a .swf file using code that picks apart the SWF manually. In my case I used this PHP class, which you can integrate nice and easily as follows:

$data = @getimagesize($filename); if ($data) list($width, $height) = $data; else { require_once ROOT_PATH . 'include/swfheader.class.php'; $swf = new swfheader(); if ($swf->loadswf($filename)) { $width = $swf->width; $height = $swf->height; } unset($swf); }

It’s not the prettiest solution, however any extra overhead will disappear automatically once getimagesize() is working again. If you’re performance conscious then you should be caching or storing the width and height of flash-files, regardless of whether getimagesize() is working or not, as most SWFs are compressed so fetching the width and height is not only an extra file-system call, but a fairly expensive one for trivial data. One problem with this solution is that it has no support for the newer LMZA compression for SWF’s (introduced by SWF container version 15 which Flash CS6 can now use).