public static function move_from_file_tmp(Model_FileTmp $file_tmp, $new_filename_prefix = '', $upload_type = 'img') { $file = static::forge(); $file->name = $file_tmp->name; if ($new_filename_prefix) { $file->name = Site_Upload::change_filename_prefix($file_tmp->name, $new_filename_prefix); } $file->filesize = $file_tmp->filesize; $file->original_filename = $file_tmp->original_filename; $file->type = $file_tmp->type; $file->member_id = $file_tmp->member_id; $file->user_type = $file_tmp->user_type; if (!is_null($file_tmp->exif)) { $file->exif = $file_tmp->exif; } if (!empty($file_tmp->shot_at)) { $file->shot_at = $file_tmp->shot_at; } $file->save(); if (conf('upload.storageType') == 'db') { $file_bin = Model_FileBin::get4name($file_tmp->name); $file_bin->name = $file->name; $file_bin->save(); } elseif (conf('upload.storageType') == 'S3') { Site_S3::move($file_tmp->name, $file->name, $upload_type); } $file_tmp->delete(); return $file; }
protected function setUp() { if (!($this->files = \Model_FileTmp::find('all'))) { \Util_Develop::output_test_info(__FILE__, __LINE__); $this->markTestSkipped('No data.'); } }
/** * Usage (from command line): * * php oil r filetmp:clean * * @return string */ public static function clean($lifetime = null) { if (is_null($lifetime)) { $lifetime = conf('upload.tmp_file.lifetime'); } $limit = conf('upload.tmp_file.delete_record_limit'); $file_tmps = \Model_FileTmp::query()->where('created_at', '<', date('Y-m-d H:i:s', time() - $lifetime))->order_by('id', 'asc')->rows_limit($limit)->get(); $i = 0; foreach ($file_tmps as $file_tmp) { if ($file_tmp->delete()) { $i++; } } return $i . ' file_tmps removed.'; }
public function check_real_file_tmp_info($file_path) { $file_info = File::file_info($file_path); $file_name = $file_info['basename']; $file = Model_FileTmp::get4name($file_name); // file に対応する Model_File が存在する $this->assertNotEmpty($file); $is_thumbnail = Util_file::get_path_partial($file_info['dirname'], 1) == 'thumbnail'; // path の確認 $length = $is_thumbnail ? 3 : 2; $offset = $is_thumbnail ? 1 : 0; $this->assertEquals(trim($file->path, '/'), Util_file::get_path_partial($file_info['dirname'], $length, $offset)); // type の確認 if ($file_info['mimetype'] != 'application/zip') { $this->assertEquals($file->type, $file_info['mimetype']); } // size の確認 if (!$is_thumbnail) { $this->assertEquals($file->filesize, $file_info['size']); } }
public static function get_file_tmps_uploaded($member_id = null, $check_selected = false, $type = 'img', $check_file_exists = true, $is_delete_not_exists_file = false) { $file_tmps = array(); $post_key = $type == 'img' ? 'image_tmp' : 'file_tmp'; if (!($file_tmps_posted = Input::post($post_key))) { if ($check_selected) { throw new HttpInvalidInputException('File not selected.'); } return array(); } if (!($file_tmp_ids = Util_Array::cast_values(array_keys($file_tmps_posted), 'int', true))) { throw new HttpInvalidInputException('Invalid input data.'); } if (!($file_tmps = Model_FileTmp::get4ids($file_tmp_ids))) { throw new FuelException('ファイルが選択されていません。'); } foreach ($file_tmps as $key => $file_tmp) { if ($member_id && $file_tmp->member_id != $member_id) { throw new HttpForbiddenException(); } if ($file_tmps_posted[$file_tmp->id] != $file_tmp->name) { throw new HttpInvalidInputException('Invalid input data.'); } $file_tmps_description_posted = Input::post($post_key . '_description'); if (isset($file_tmps_description_posted[$file_tmp->id])) { $file_tmps[$key]->description = trim($file_tmps_description_posted[$file_tmp->id]); } $file_tmp_path = Site_Upload::get_uploaded_file_path($file_tmp->name, 'raw', 'img', true); if (conf('upload.storageType') == 'normal' && !file_exists($file_tmp_path)) { if ($check_file_exists) { throw new HttpInvalidInputException('File not exists.'); } if ($is_delete_not_exists_file) { $file_tmp->delete(); } unset($file_tmps[$file_tmp->id]); } } return $file_tmps; }
protected function common_FileTmp_delete_upload($upload_type = 'img') { $this->controller_common_api(function () use($upload_type) { $id = (int) Input::post('id'); $file_tmp = Model_FileTmp::check_authority($id, $this->u->id, null, 'member_id', IS_ADMIN ? 1 : 0); $options = Site_Upload::get_upload_handler_options($this->u->id, IS_ADMIN, true, null, 0, true, $upload_type); $uploadhandler = new MyUploadHandler($options, false); \DB::start_transaction(); $this->response_body = $uploadhandler->delete(false, $file_tmp); \DB::commit_transaction(); return $this->response_body; }); }
public function delete($print_response = true, Model_FileTmp $file_tmp = null) { $response = array(); if ($file_tmp) { $response[$file_tmp->name] = $this->delete_file($file_tmp->name, $this->options['storage_type']) && $file_tmp->delete(); } return $this->generate_response($response, $print_response); }