Esempio n. 1
0
 public function ShowAction($id = '')
 {
     global $CONFIG;
     $id += 0;
     if (!$id) {
         throw new ApplicationException("404 File Not Found");
     }
     $size = reqs('size');
     $is_preview = reqi('preview');
     if ($is_preview) {
         $item = $this->model->one($id);
         if ($item['is_image']) {
             $this->model->transmit_file($id, $size, 'inline');
         } else {
             #if it's not an image and requested preview - return std image
             $filepath = $CONFIG['site_root'] . '/img/att_file.png';
             # TODO move to web.config or to model?
             header('Content-type: ' . UploadUtils::get_mime4ext($item['ext']));
             $fp = fopen($filepath, 'rb');
             fpassthru($fp);
         }
     } else {
         $this->model->transmit_file($id, $size, 'inline');
     }
 }
Esempio n. 2
0
 public function transmit_file($id, $size = '', $disposition = 'attachment')
 {
     $item = $this->one($id);
     #validation
     if (!count($item)) {
         throw new ApplicationException('No file specified');
     }
     if ($item['status'] != 0) {
         throw new ApplicationException('Access Denied');
     }
     $size = UploadUtils::check_size($size);
     $filepath = $this->get_upload_path($id, $item['ext'], $size);
     $filename = str_replace('"', "'", $item['iname']);
     #quote filename
     header('Content-type: ' . UploadUtils::get_mime4ext($item['ext']));
     header("Content-Length: " . filesize($filepath));
     header('Content-Disposition: ' . $disposition . '; filename="' . $filename . '"');
     #logger('transmit file '.$filepath." $id, $size, $disposition, ".UploadUtils::get_mime4ext($item['ext']));
     $fp = fopen($filepath, 'rb');
     fpassthru($fp);
 }