How to Fix readfile Problem on TimThumb

TimThumb is my favorite Auto Generated Thumbnail code, as it is simple to use and work’s great in almost any server.

But there are readfile function problems on some servers TimThumb auto resized imaged on the fly, the script developed by Darren Hoyt and Tweak by Ben Gillbanks,

The problem that I currently have is readfile function was disabled by Hosting Server Administrator, they said they disabled this function for security reason.

So I was Googling to find out how to fix this problem.

After searching with several different keyword combinations, I came across the best solution from OJAK AJA, and here is what we must do.

Open your TimThumb script and find this code (around line 496 on version 1.12)

1
readfile( $cache_file );

Then you need replace readfile function with file_get_contents, Sigiro said, this is the best method, beside file_gets_contents, there are several PHP Functions we can use, such as fpassthru, back to this tricks, to make your TimThumb work, replace code above with this code

1
2
$img_data file_get_contents$cache_file );
 echo $img_data;

And you are done, this trick works like a charm in my server client. I hope this trick to fix Readfile Problem on TimThumb has worked out for you too

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>