You are here

function pCache::writeToCache in Visitors 7

Same name and namespace in other branches
  1. 8 pchart/pCache.inc \pCache::WriteToCache()
  2. 7.2 pChart/class/pCache.class.php \pCache::writeToCache()
  3. 7.0 pchart/pCache.inc \pCache::WriteToCache()

File

pChart/class/pCache.class.php, line 50

Class

pCache

Code

function writeToCache($ID, $pChartObject) {

  /* Compute the paths */
  $TemporaryFile = $this->CacheFolder . "/tmp_" . rand(0, 1000) . ".png";
  $Database = $this->CacheFolder . "/" . $this->CacheDB;
  $Index = $this->CacheFolder . "/" . $this->CacheIndex;

  /* Flush the picture to a temporary file */
  imagepng($pChartObject->Picture, $TemporaryFile);

  /* Retrieve the files size */
  $PictureSize = filesize($TemporaryFile);
  $DBSize = filesize($Database);

  /* Save the index */
  $Handle = fopen($Index, "a");
  fwrite($Handle, $ID . "," . $DBSize . "," . $PictureSize . "," . time() . ",0      \r\n");
  fclose($Handle);

  /* Get the picture raw contents */
  $Handle = fopen($TemporaryFile, "r");
  $Raw = fread($Handle, $PictureSize);
  fclose($Handle);

  /* Save the picture in the solid database file */
  $Handle = fopen($Database, "a");
  fwrite($Handle, $Raw);
  fclose($Handle);

  /* Remove temporary file */
  unlink($TemporaryFile);
}