Ejemplo n.º 1
0
 public function save($uploaded_file_path = null)
 {
     try {
         if (!$uploaded_file_path) {
             $uploaded_file_path = $this->upload_file();
         }
         $this->set_file_properties($uploaded_file_path);
         if (!Site_Upload::check_and_make_uploaded_dir($this->options['upload_dir'], null, $this->options['path_chmod'])) {
             throw new FuelException('ディレクトリの作成に失敗しました。');
         }
         $tmp_file_path = APPPATH . 'tmp/' . $this->file->name;
         if (!Util_file::move($uploaded_file_path, $tmp_file_path)) {
             throw new FuelException('Save raw file error.');
         }
         // exif データの取得
         $exif = array();
         if ($this->options['is_save_exif_to_db'] && $this->file->type == 'image/jpeg') {
             $exif = \Util_Exif::get_exif($tmp_file_path, $this->options['exif_accept_tags'], $this->options['exif_ignore_tags']);
         }
         $is_resaved = false;
         // 回転状態の補正
         if ($this->options['auto_orient'] && !empty($exif['Orientation'])) {
             Util_file::correct_orientation($tmp_file_path, $exif['Orientation']);
             $is_resaved = true;
         }
         // 大きすぎる場合はリサイズ & 保存ファイルから exif 情報削除
         $file_size_before = $this->file->size;
         if ($max_size = Site_Upload::get_accepted_max_size($this->options['member_id'])) {
             $this->file->size = Site_Upload::check_max_size_and_resize($tmp_file_path, $max_size);
             $is_resaved = $this->file->size != $file_size_before;
         }
         if ($this->options['is_clear_exif_on_file'] && !$is_resaved) {
             Site_Upload::clear_exif($tmp_file_path);
             $this->file->size = File::get_size($tmp_file_path);
         }
         $this->save_model_file($exif);
         $this->save_file_bin($tmp_file_path);
     } catch (\FuelException $e) {
         if (isset($this->file->file_path) && file_exists($this->file->file_path)) {
             Util_file::remove($this->file->file_path);
             $this->file->size = filesize($this->file->file_path);
         }
         $this->file->error = $e->getMessage();
     }
     return $this->file;
 }
Ejemplo n.º 2
0
 public static function make_and_remove_thumbnails($moved_files, $additional_sizes_key = null)
 {
     foreach ($moved_files as $moved_file) {
         if (!empty($moved_file['to']) && !empty($moved_file['filepath_prefix'])) {
             Site_Upload::make_thumbnails($moved_file['to'], $moved_file['filepath_prefix'], true, $additional_sizes_key);
         }
         if (!empty($moved_file['from']) && file_exists($moved_file['from'])) {
             Util_file::remove($moved_file['from']);
         }
         if (!empty($moved_file['from_thumbnail'])) {
             Util_file::remove($moved_file['from_thumbnail']);
         }
     }
 }
Ejemplo n.º 3
0
 public static function remove_raw_file($filename, $is_tmp = false)
 {
     $file = self::get_uploaded_file_path($filename, 'raw', 'file', $is_tmp);
     Util_file::remove($file);
     return true;
 }
Ejemplo n.º 4
0
 private static function execute_clean_file($file_type, $is_tmp = false)
 {
     if (!self::$absolute_execute && !\Site_Util::check_is_dev_env()) {
         throw new \FuelException('This task is not work at prod env.');
     }
     $raw_file_dir_path = \Site_Upload::get_uploaded_path('raw', $file_type, $is_tmp);
     $cache_file_dir_path_key = 'upload.types.' . $file_type;
     if ($is_tmp) {
         $cache_file_dir_path_key .= '.tmp';
     }
     $cache_file_dir_path_key .= '.root_path.cache_dir';
     $cache_file_dir_path = DOCROOT . conf($cache_file_dir_path_key);
     if (!file_exists($raw_file_dir_path) && ($cache_file_dir_path && !file_exists($cache_file_dir_path))) {
         return "File directry '" . $raw_file_dir_path . "' not exists.";
     }
     $file_paths = \Util_file::get_file_recursive($raw_file_dir_path);
     if ($cache_file_dir_path) {
         $file_paths = array_merge($file_paths, \Util_file::get_file_recursive($cache_file_dir_path));
     }
     if (!$file_paths) {
         return sprintf("No files at '%s'", $raw_file_dir_path);
     }
     $i = 0;
     foreach ($file_paths as $file_path) {
         if (self::check_file_exists_record($file_path, $is_tmp)) {
             continue;
         }
         \Util_file::remove($file_path);
         $i++;
     }
     $subject = $file_type;
     if ($is_tmp) {
         $subject .= '_tmp';
     }
     return sprintf('%d %s removed.', $i, $subject);
 }