[Solar-talk] use getimagesize() in a view

Antti Holvikari anttih at gmail.com
Mon May 12 11:07:06 CDT 2008


On Mon, May 12, 2008 at 6:22 PM, Jeff Surgeson <solar at 3hex.com> wrote:
> How do I get php's getimagesize() to find a public image file?
>
> I assumed that passing it a path same as I would if I used a Solar image
> helper as in:
>
> echo $this->image('path/to/image.jpg'); it finds this!
> $image_info = getimagesize('path/to/image.jpg'); not this!
>
> If I put image.jpg in my document root then getimagesize() finds it, so I am
> calling the function ok it just cant find the file. I assume this has to do
> with public paths symbolic links etc. I have my directory layout and symbolic
> links done as per standard (/source /include /config etc) which work fine for
> all else.

This is how I've done it:

Create a new config key to the class where you're calling
getimagesize(). Something like 'image_path'.

Then in your config file you can set it relative to the image path.

$config['Vendor_Class']['image_path'] = dirname(dirname(__FILE__)) . '/images';

Then just call getimagesize($this->_config['image_path'] . '/' . $image);

In my case the class is a view helper which needs to check if an image exists.

Hope that helps.

-- 
Antti Holvikari <http://anttih.com>


More information about the Solar-talk mailing list