/** * 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) { $filename = self::save($file); if (APPENV == 'frontend') { $upl_dir = str_replace('frontend', 'backend', Kohana::config('upload.directory')); if (!copy($filename, $upl_dir . basename($filename))) { Kohana::log('error', "COPY FAILED: copy({$filename}, {$upl_dir}.basename({$filename}))"); } } $pp = pathinfo($filename); $ext = $pp['extension']; $file_type = self::check_filetype($file_data['type'], $filename); $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['date_added'] = date('Y-m-d H:i:s'); if ($upload_data['is_image']) { $properties = file::get_image_properties($filename); if (!empty($properties)) { $upload_data = array_merge($upload_data, $properties); } } return $upload_data; }
/** * 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; }
/** * generate a preview image * * @param string $upload_data * @return void * @author Andy Bennett */ public function save_preview($upload_data, $filename) { $pp = pathinfo($filename); $preview_data = $upload_data; $preview_data['file_name'] = $pp['basename']; $preview_data['file_type'] = 'image/jpeg'; $preview_data['full_path'] = $filename; $preview_data['raw_name'] = $pp['filename']; $preview_data['file_ext'] = '.jpg'; $preview_data['file_size'] = filesize($filename); $preview_data['is_image'] = true; $preview_data['is_audio'] = false; $preview_data['is_video'] = false; $preview_data['date_added'] = date('Y-m-d H:i:s'); $properties = file::get_image_properties($filename); if (!empty($properties)) { $preview_data = array_merge($preview_data, $properties); } return $preview_data; }