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; }