Class ‘PhpThumb’ not found in Plugin File

May 29, 2012

Ran into an odd error today, working with PHP My Directory and the PhpThumb Library.

The initial error was:

[23-Apr-2012 11:34:41] PHP Fatal error: Class 'PhpThumb' not found in /public_html/directory/includes/phpThumb/thumb_plugins/ on line 36
[23-Apr-2012 11:38:26] PHP Fatal error: Class 'PhpThumb' not found in /public_html/directory/includes/phpThumb/thumb_plugins/ on line 179

After spending way too much time debugging, as well as banging my head on the desk trying to figure out how come even “class_exists” was returning true, but I was still getting an error, I finally realized that today was NOT the 23rd of April.

However, that WAS the content of the error_log file in the plugin directory.

So, PHPThumb was attempting to load/read the error_log file. I created a test file, named “test” with only the word “test” in it and saved it to the plguin directory. Sure enough, this file was read and printed sometime during the PHP Thumb processes.


As it turns out, the PHPThumb Library searches the plugin directory and loads all files, except those that are ‘.’, ‘..’, or ‘.svn’.

This occurs in “,” around line 205 in the “loadPlugins” function.

So, essentially anything that is in the plugin directory, php file or not, gets read using “include_once.”


To fix this, I added a quick check to make sure the file name contains “.php”, changing line 217 from:

if ($file == '.' || $file == '..' || $file == '.svn')


if ($file == '.' || $file == '..' || $file == '.svn' || stristr($file, ".php") === false)

The “stristr” ensures that only php files are loaded.

Possible Problems with this Fix

In this situation, there are only two plugins and they are both php files in the directory. It could be simplified a bit too.

However, depending on what plugins you are using for PHP Thumb or how they are ordered, this might not work.

You would need to make sure that all of your plugins are in the plugin directory and contain “.php” in them.

With that said, I think this should be fairly safe to use and call fixed. The “loadPlugins” function is only called once and opendir and readdir are used to read all the files in the passed directory. If directories were ever passed to it too, or in the “thumb_plugins” folder, I don’t think “include_once” would not work.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s