Beispiel #1
0
$resizedImage = $pathInfo['filename'] . '-' . $x . '-' . $y . ($crop ? '-c' : '') . '.' . $pathInfo['extension'];
if (!$x && !$y) {
    $resizedImage = $image;
}
//resized image path
$resizedImagepathFS = PATH_MODULES_FILES_FS . '/' . $module . '/' . $location . '/' . $resizedImage;
//if file already exists, no need to resize file send it
if (file_exists($resizedImagepathFS)) {
    //check If-Modified-Since header if exists then return a 304 if needed
    if (isset($_SERVER['IF-MODIFIED-SINCE'])) {
        $ifModifiedSince = strtotime($_SERVER['IF-MODIFIED-SINCE']);
    } elseif (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
        $ifModifiedSince = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
    }
    if (isset($ifModifiedSince) && filemtime($resizedImagepathFS) <= $ifModifiedSince) {
        $filetype = CMS_file::mimeContentType($resizedImagepathFS);
        $filetype = $filetype ? $filetype : 'application/octet-stream';
        header('HTTP/1.1 304 Not Modified');
        header('Content-Type: ' . $filetype);
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($resizedImagepathFS)) . ' GMT');
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 2592000) . ' GMT');
        //30 days
        header("Cache-Control: must-revalidate");
        header("Pragma: public");
        exit;
    }
    //Send cache headers
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($resizedImagepathFS)) . ' GMT');
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 2592000) . ' GMT');
    //30 days
    header("Cache-Control: must-revalidate");
 /**
  * Send a given file for download (inline or attachment)
  *
  * @param string $source : the file to download (FS relative)
  * @param boolean $inline : the file is sent inline (default) or as attachment
  * @param boolean $deleteFile : delete the sended file at end of download (default : false)
  * @param mixed $forceContentType : false to auto get the mime type to send, or string to force a mime type
  * @return void or false if error
  * @access public
  * @static
  */
 function downloadFile($source, $inline = true, $deleteFile = false, $forceContentType = false)
 {
     if (!file_exists($source)) {
         CMS_grandFather::raiseError('Source file to send does not exists : ' . $source);
         return false;
     }
     if (connection_status() != 0) {
         CMS_grandFather::raiseError('Error connexion status is not "normal" : ' . connection_status());
         return false;
     }
     //get mime filetype
     if (!$forceContentType) {
         $filetype = CMS_file::mimeContentType($source);
         $filetype = $filetype ? $filetype : 'application/octet-stream';
     } else {
         $filetype = $forceContentType;
     }
     //close session then clean buffer
     @session_write_close();
     @ob_end_clean();
     //to prevent long file from getting cut off from max_execution_time
     @set_time_limit(0);
     //send http headers
     header("Cache-Control: public", true);
     //This is needed to avoid bug with IE in HTTPS
     header("Pragma:", true);
     //This is needed to avoid bug with IE in HTTPS
     header('Content-Type: ' . $filetype);
     header("Content-transfer-encoding: binary");
     clearstatcache();
     //to avoid bug on filesize
     header('Content-Length: ' . (string) filesize($source));
     header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . '; filename="' . basename($source) . '"');
     //If mod_xsendfile exists, use it to send files
     if (!$deleteFile && (isset($_SERVER["REDIRECT_ATM_X_SENDFILE"]) && $_SERVER["REDIRECT_ATM_X_SENDFILE"] == 1 || getenv('ATM_X_SENDFILE') == 1)) {
         header('X-Sendfile: ' . $source);
         exit;
     }
     //send file
     if ($file = fopen($source, 'rb')) {
         while (!feof($file) && connection_status() == 0) {
             print fread($file, 1024 * 8);
             flush();
         }
         fclose($file);
     }
     if ($deleteFile) {
         //delete source file
         @unlink($source);
     }
     exit;
 }