You are here

function resizeimage_wrapper_filecache in Brilliant Gallery 6.2

Same name and namespace in other branches
  1. 5.4 image.php \resizeimage_wrapper_filecache()
  2. 5.3 image.php \resizeimage_wrapper_filecache()
  3. 6 image.php \resizeimage_wrapper_filecache()
1 call to resizeimage_wrapper_filecache()
image.php in ./image.php

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;
}