Пример #1
0
 /**
  * 'Opens' the requested file in the current window as an attachment,
  * which pops up the "Save file as" dialog.
  *
  * @TODO test this to make sure it works in all browsers.
  *
  * @return void
  */
 public function downloadScreenshot()
 {
     include_once HV_ROOT_DIR . '/../src/Database/ImgIndex.php';
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerLayers.php';
     $imgIndex = new Database_ImgIndex();
     $info = $imgIndex->getScreenshot($this->_params['id']);
     $layers = new Helper_HelioviewerLayers($info['dataSourceString']);
     $dir = sprintf('%s/screenshots/%s/%s/', HV_CACHE_DIR, str_replace('-', '/', substr($info['timestamp'], 0, 10)), $this->_params['id']);
     $filename = sprintf('%s_%s.png', str_replace(array(':', '-', ' '), '_', $info['observationDate']), $layers->toString());
     $filepath = $dir . $filename;
     // If screenshot is no longer cached, regenerate it.
     if (!@file_exists($filepath)) {
         $this->reTakeScreenshot($this->_params['id']);
         if (!@file_exists($filepath)) {
             $filepath = str_replace(HV_CACHE_DIR, '', $filepath);
             throw new Exception('Unable to locate the requested file: ' . $filepath, 24);
         }
     }
     // Set HTTP headers
     header('Pragma: public');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     // required for certain browsers
     header('Cache-Control: private', false);
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . @filesize($filepath));
     header('Content-type: image/png');
     echo file_get_contents($filepath);
 }