Пример #1
0
 public function get($id_media)
 {
     // Pictures data from database
     $picture = $id_media ? $this->media_model->get($id_media) : FALSE;
     $options = $this->uri->uri_to_assoc();
     unset($options['get']);
     if (empty($options['size'])) {
         $options['size'] = 120;
     }
     // Path to the picture
     if ($picture && file_exists($picture_path = DOCPATH . $picture['path'])) {
         $thumb_path = DOCPATH . Settings::get('files_path') . str_replace(Settings::get('files_path') . '/', '/.thumbs/', $picture['base_path']);
         $thumb_file_path = $this->medias->get_thumb_file_path($picture, $options);
         $refresh = !empty($options['refresh']) ? TRUE : FALSE;
         // If no thumb, try to create it
         if (!file_exists($thumb_file_path) or $refresh === TRUE) {
             try {
                 $thumb_file_path = $this->medias->create_thumb(DOCPATH . $picture['path'], $thumb_file_path, $options);
             } catch (Exception $e) {
                 // $return_thumb_path = FCPATH.'themes/'.Settings::get('theme_admin').'/styles/'.Settings::get('backend_ui_style').'/images/icon_48_no_folder_rights.png';
             }
         }
         $mime = get_mime_by_extension($thumb_file_path);
         $content = read_file($thumb_file_path);
         $this->push_thumb($content, $mime, 0);
     } else {
         $mime = 'image/png';
         $content = read_file(FCPATH . 'themes/' . Settings::get('theme_admin') . '/styles/' . Settings::get('backend_ui_style') . '/images/icon_48_no_source_picture.png');
         $this->push_thumb($content, $mime, 0);
     }
 }
Пример #2
0
 public function get_thumb($id)
 {
     // Pictures data from database
     $picture = $id ? $this->media_model->get($id) : FALSE;
     // Path to the picture
     if ($picture && file_exists($picture_path = DOCPATH . $picture['path'])) {
         $thumb_path = DOCPATH . Settings::get('files_path') . str_replace(Settings::get('files_path') . '/', '/.thumbs/', $picture['base_path']);
         $return_thumb_path = $thumb_path . $picture['file_name'];
         // If no thumb, try to create it
         if (!file_exists($thumb_path . $picture['file_name'])) {
             $settings = array('size' => Settings::get('media_thumb_size') != '' ? Settings::get('media_thumb_size') : 120, 'unsharpmask' => false);
             try {
                 $return_thumb_path = $this->medias->create_thumb(DOCPATH . $picture['path'], $thumb_path . $picture['file_name'], $settings);
             } catch (Exception $e) {
                 $return_thumb_path = FCPATH . 'themes/' . Settings::get('theme_admin') . '/styles/' . Settings::get('backend_ui_style') . '/images/icon_48_no_folder_rights.png';
             }
         }
         $mime = get_mime_by_extension($return_thumb_path);
         $content = read_file($return_thumb_path);
         self::push_thumb($content, $mime, 0);
     } else {
         $mime = 'image/png';
         $content = read_file(FCPATH . 'themes/' . Settings::get('theme_admin') . '/styles/' . Settings::get('backend_ui_style') . '/images/icon_48_no_source_picture.png');
         self::push_thumb($content, $mime, 0);
     }
 }
Пример #3
0
 /**
  * Download media with given ID
  *
  * @param   int     $id_media
  * @param   string  $hash       SHA-1 hash to verify a valid (intentionally public) download link
  */
 public function download($id_media, $hash)
 {
     $id_media = (int) $id_media;
     if ($hash !== sha1($id_media . config_item('encryption_key'))) {
         show_error('Access Denied');
     }
     $media = $id_media ? $this->media_model->get($id_media) : FALSE;
     $filePath = substr(BASEPATH, 0, -7) . $media['path'];
     if ($id_media === 0 || !file_exists($filePath)) {
         show_404();
     }
     header('Content-length: ' . filesize($filePath));
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename="' . $media['file_name'] . '"');
     die(file_get_contents($filePath));
 }