Contact Lifestream



Thumbnail Caching

I’ve added a caching routine to the Video Database thumbnail function as well as cleaned up some of the code with the Coppermine thumbnail. It seemed like a bad idea to keep calling GD every time someone accessed a document. Especially since the thumbnail is now on EVERY page.
Simple image and flat file caching in PHP can be done with filemtime.

if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) {
   return file;
} else {
   // stuff for creating thumbnail and writing $cachefile
   return file;
}

Also, that means no more header. I just return the filename. For some reason, sending vars via GET resulted in errors on occasion. imagejpeg only works in one of two ways, either by writing the data to disk or by using header to get the raw data sent directly to the client. So that is another reason, apart from saving bandwidth.