コード例 #1
0
 /**
  * get full information for an upload
  *
  * @param string $file 
  * @param array $file_data 
  * @return array
  * @author Andy Bennett
  */
 function get_upload_data($file, $file_data, $save = true)
 {
     $filename = $save ? upload::save($file_data) : $file;
     if (!strlen($filename)) {
         throw new Exception("Empty filename", 1);
     }
     $pp = pathinfo($filename);
     $ext = strtolower($pp['extension']);
     $file_type = uploads::check_filetype($file_data['type'], $filename, $ext);
     $d = Kohana::config('upload.directory');
     $upload_data['file_name'] = $pp['basename'];
     $upload_data['file_type'] = $file_type;
     $upload_data['file_path'] = $d;
     $upload_data['full_path'] = $filename;
     $upload_data['raw_name'] = $pp['filename'];
     $upload_data['orig_name'] = $file_data['name'];
     $upload_data['file_ext'] = '.' . strtolower($ext);
     $upload_data['file_size'] = $file_data['size'];
     $upload_data['is_image'] = file::is_image($file_type);
     $upload_data['is_video'] = 0;
     $upload_data['is_audio'] = 0;
     $upload_data['date_added'] = date('Y-m-d H:i:s');
     $upload_data['preview'] = false;
     $driver = uploads::get_driver($upload_data['is_image'], $file_type, $ext);
     if ($driver !== false) {
         // Load the driver
         if (Kohana::auto_load($driver)) {
             // Initialize the driver
             $upload_driver = new $driver();
             // Validate the driver
             if (!$upload_driver instanceof Uploader_Driver) {
                 throw new Kohana_Exception('core.driver_implements', $driver, 'upload', 'Uploader_Driver');
             }
             $upload_driver->generate_preview($upload_data, $filename, $ext);
         }
     }
     if ($upload_data['is_image']) {
         $properties = file::get_image_properties($filename);
         if (!empty($properties)) {
             $upload_data = array_merge($upload_data, $properties);
         }
     }
     return $upload_data;
 }
コード例 #2
0
 /**
  * undocumented function
  *
  * @param string $path 
  * @return void
  * @author Andy Bennett
  */
 protected function render($path, $download = false, $orig_name = null)
 {
     Kohana::close_buffers(false);
     if (is_null($orig_name)) {
         $orig_name = basename($path);
     }
     $file_type = uploads::check_filetype(file::mime($path), $path);
     header('Content-type: ' . $file_type);
     if (!file::is_image($file_type) or $download) {
         header('Content-Disposition: attachment; filename="' . $orig_name . '"');
     }
     header("Content-Length: " . filesize($path));
     readfile($path);
     exit;
 }