function resizeimage_wrapper_filecache in Brilliant Gallery 5.4
Same name and namespace in other branches
- 5.3 image.php \resizeimage_wrapper_filecache()
- 6 image.php \resizeimage_wrapper_filecache()
- 6.2 image.php \resizeimage_wrapper_filecache()
File
- ./
image.php, line 46
Code
function resizeimage_wrapper_filecache() {
global $bgcachexpire;
$bgcacheid = 'bg_' . md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
#echo $bgcacheid;
#echo '. 0.... ';
# Tested that both relative (eg sites/all/files/cache) and absolute (eg /home/data/tmp) tmp path settings work OK here.
$cachedfile = file_directory_temp() . '/' . $bgcacheid;
#$cachedfile = realpath(file_directory_temp() . '/' . $bgcacheid);
#echo file_directory_temp() . '/' . $bgcacheid;
#echo " .... ";
#echo $cachedfile;
# See http://drupal.org/node/194923
$lastchanged = file_exists($cachedfile) ? filemtime($cachedfile) : false;
if ($lastchanged === false or time() - $lastchanged > $bgcachexpire) {
#echo '. 1.... ';
# Cache file does not exist or is too old.
$my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh']);
# Now put $my_data to cache!
$fh = fopen($cachedfile, "w+");
fwrite($fh, $my_data);
fclose($fh);
#test
/*
$my_data_t = unserialize( $my_data );
$fh = fopen( $cachedfile . '_2', "w+" );
fwrite( $fh, $my_data_t[1] );
fclose( $fh );
*/
$my_data = unserialize($my_data);
}
else {
#echo '. 2.... ';
# Cache file exists.
$my_data = unserialize(file_get_contents($cachedfile));
}
return $my_data;
}