示例#1
0
    // send any non 200 status
    if ($data['status'] != 200) {
        header('HTTP/1.0 ' . $data['status'] . ' ' . $data['statusmessage']);
    }
    // die on errors
    if ($data['status'] > 203) {
        print $data['statusmessage'];
        exit;
    }
}
$evt->advise_after();
unset($evt);
//handle image resizing/cropping
if (substr($MIME, 0, 5) == 'image' && $WIDTH) {
    if ($HEIGHT) {
        $data['file'] = $FILE = media_crop_image($data['file'], $EXT, $WIDTH, $HEIGHT);
    } else {
        $data['file'] = $FILE = media_resize_image($data['file'], $EXT, $WIDTH, $HEIGHT);
    }
}
// finally send the file to the client
$evt = new Doku_Event('MEDIA_SENDFILE', $data);
if ($evt->advise_before()) {
    sendFile($data['file'], $data['mime'], $data['download'], $data['cache']);
}
// Do something after the download finished.
$evt->advise_after();
/* ------------------------------------------------------------------------ */
/**
 * Set headers and send the file to the client
 *
 /**
  * Override the mpdf _getImage function
  *
  * This function takes care of gathering the image data from HTTP or
  * local files before passing the data back to mpdf's original function
  * making sure that only cached file paths are passed to mpdf. It also
  * takes care of checking image ACls.
  */
 function _getImage(&$file, $firsttime = true, $allowvector = true, $orig_srcpath = false)
 {
     global $conf;
     // build regex to parse URL back to media info
     $re = preg_quote(ml('xxx123yyy', '', true, '&', true), '/');
     $re = str_replace('xxx123yyy', '([^&\\?]*)', $re);
     // extract the real media from a fetch.php uri and determine mime
     if (preg_match("/^{$re}/", $file, $m) || preg_match('/[&\\?]media=([^&\\?]*)/', $file, $m)) {
         $media = rawurldecode($m[1]);
         list($ext, $mime) = mimetype($media);
     } else {
         list($ext, $mime) = mimetype($file);
     }
     // local files
     $local = '';
     if (substr($file, 0, 9) == 'dw2pdf://') {
         // support local files passed from plugins
         $local = substr($file, 9);
     } elseif (!preg_match('/(\\.php|\\?)/', $file)) {
         $re = preg_quote(DOKU_URL, '/');
         // directly access local files instead of using HTTP, skip dynamic content
         $local = preg_replace("/^{$re}/i", DOKU_INC, $file);
     }
     if (substr($mime, 0, 6) == 'image/') {
         if (!empty($media)) {
             // any size restrictions?
             $w = $h = 0;
             if (preg_match('/[\\?&]w=(\\d+)/', $file, $m)) {
                 $w = $m[1];
             }
             if (preg_match('/[\\?&]h=(\\d+)/', $file, $m)) {
                 $h = $m[1];
             }
             if (media_isexternal($media)) {
                 $local = media_get_from_URL($media, $ext, -1);
                 if (!$local) {
                     $local = $media;
                 }
                 // let mpdf try again
             } else {
                 $media = cleanID($media);
                 //check permissions (namespace only)
                 if (auth_quickaclcheck(getNS($media) . ':X') < AUTH_READ) {
                     $file = '';
                 }
                 $local = mediaFN($media);
             }
             //handle image resizing/cropping
             if ($w && file_exists($local)) {
                 if ($h) {
                     $local = media_crop_image($local, $ext, $w, $h);
                 } else {
                     $local = media_resize_image($local, $ext, $w, $h);
                 }
             }
         } elseif (media_isexternal($file)) {
             // fixed external URLs
             $local = media_get_from_URL($file, $ext, $conf['cachetime']);
         }
         if ($local) {
             $file = $local;
             $orig_srcpath = $local;
         }
     }
     return parent::_getImage($file, $firsttime, $allowvector, $orig_srcpath);
 }
示例#3
0
文件: fetch.php 项目: lorea/Hydra-dev
        exit;
    }
    $FILE = mediaFN($MEDIA);
}
//check file existance
if (!@file_exists($FILE)) {
    header("HTTP/1.0 404 Not Found");
    //FIXME add some default broken image
    print 'Not Found';
    exit;
}
$ORIG = $FILE;
//handle image resizing/cropping
if (substr($MIME, 0, 5) == 'image' && $WIDTH) {
    if ($HEIGHT) {
        $FILE = media_crop_image($FILE, $EXT, $WIDTH, $HEIGHT);
    } else {
        $FILE = media_resize_image($FILE, $EXT, $WIDTH, $HEIGHT);
    }
}
// finally send the file to the client
$data = array('file' => $FILE, 'mime' => $MIME, 'download' => $DL, 'cache' => $CACHE, 'orig' => $ORIG, 'ext' => $EXT, 'width' => $WIDTH, 'height' => $HEIGHT);
$evt = new Doku_Event('MEDIA_SENDFILE', $data);
if ($evt->advise_before()) {
    sendFile($data['file'], $data['mime'], $data['download'], $data['cache']);
}
/* ------------------------------------------------------------------------ */
/**
 * Set headers and send the file to the client
 *
 * @author Andreas Gohr <andi@splitbrain.org>