EllisLab text mark
Advanced Search
     
Imgsizer - uncaught “read” error solution
Posted: 02 June 2010 08:21 PM   [ Ignore ]
Joined: 2010-01-06
11 posts

Hello!

I just wanted to share a fix to an uncaught “read” error that may be haunting some of you.

Imgsizer version: 2.6
EE version: 2.0.2pb01

The Scenario

I am using the imgsizer plugin to display profile images. The error occurs when a profile image doesn’t exist and a {photo_url} (or any path) is set in the “src” parameter.

Example:

{exp:imgsizer:size src="images/member_photos/{photo_filename}" width="100"

PHP throws a “read” error because it can’t read the nonexistent “file”.

I tried to get around the error using conditional template tags and a few other template tricks, but EE parses {exp} tags before anything else, so the error persisted.

In the end, the plugin needed to do the work and check to see if a file was actually given, and not just a path. Here are my updates:

// -------------------------------------
// collect passed vars from the tag
// -------------------------------------
$src = ( ! $this->EE->TMPL->fetch_param('image')) ? ( !$this->EE->TMPL->fetch_param('src') ? '' $this->EE->TMPL->fetch_param('src') ) : $this->EE->TMPL->fetch_param('image');
$src str_replace(SLASH"/"$src); // clean up passed src param 
            
// Check for a file extension
$ext pathinfo($srcPATHINFO_EXTENSION);
if (!
$ext{ $src false
 
Posted: 08 July 2010 11:59 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-19
52 posts

Yes! Great stuff Sean, and thanks for this! I’ve been losing hair wondering why my conditionals weren’t working.

Hope this fix gets incorporated into the next release.

 Signature 

“The very powerful and the very stupid have one thing in common. Instead of altering their views to fit the facts, they alter the facts to fit their views…which can be very uncomfortable if you happen to be one of the facts that needs altering.” - The Doctor