public function post_parse_payments() { $config = array('path' => DOCROOT . 'uploads/csv', 'randomize' => true, 'ext_whitelist' => array('csv')); Upload::process($config); if (Upload::is_valid()) { //Upload::save(); $file = Upload::get_files(); $uploaded_file = $file[0]['file']; Package::load("excel"); $excel = PHPExcel_IOFactory::createReader('CSV')->setDelimiter(',')->setEnclosure('"')->setLineEnding("\n")->setSheetIndex(0)->load($uploaded_file); $objWorksheet = $excel->setActiveSheetIndex(0); $highestRow = $objWorksheet->getHighestRow(); $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); //read from file for ($row = 1; $row <= $highestRow; ++$row) { $file_data = array(); for ($col = 0; $col <= $highestColumnIndex; ++$col) { $value = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); $file_data[$col] = trim($value); } $result[] = $file_data; } print_r($result); } else { print "Invalid uploads"; } }
/** * アップロードファイルを指定のフォルダに移動する * * @access public * @param array $config アップロードの設定 * @return void * @author kobayashi * @author ida */ public static function moveUploadedFile($config) { $default = array('ext_whitelist' => array('jpg'), 'randomize' => true); $config = array_merge($default, $config); \Upload::process($config); $is_upload = false; $result = array(); if (\Upload::is_valid()) { \Upload::save(); $files = \Upload::get_files(); foreach ($files as $file) { $result[$file['field']] = $file; } $is_upload = true; } else { $error_files = \Upload::get_errors(); foreach ($error_files as $file) { foreach ($file['errors'] as $error) { if ($error['error'] != \Upload::UPLOAD_ERR_NO_FILE) { $result[$file['field']] = $file; $is_upload = false; } } } if (empty($result)) { $is_upload = true; } } return array($is_upload, $result); }
/** * Register * * @access public * @author Dao Anh Minh */ public function action_register() { $view = View::forge('admin/gallery/register'); $view->err = array(); $view->data = array('description' => ''); if (Input::method() == 'POST') { Upload::process($this->config); if (Upload::is_valid()) { Upload::save(); $file_name = Upload::get_files(0)['saved_as']; if (!empty($file_name)) { $img = Model_Img::forge(); $img->name = $file_name; $img->active = Input::post('active', false); $img->type = IMG_GALLERY; $img->info = serialize(array('info' => Input::post('description', ''))); $img->save(); Session::set_flash('success', 'Đăng ký hình thành công'); Response::redirect('admin/gallery'); } else { Session::set_flash('error', 'Chỉ chấp nhận file hình'); Response::redirect('admin/gallery/register'); } } else { Session::set_flash('error', 'Hình bạn chọn không phù hợp, vui lòng thử lại'); $view->data = Input::post(); } } $this->template->title = 'Đăng ký hình'; $this->template->content = $view; }
public function action_create() { if (Input::method() == 'POST') { $config = array('path' => DOCROOT . DS . 'files', 'randomize' => true, 'ext_whitelist' => array('txt')); Upload::process($config); if (Upload::is_valid()) { $file = Upload::get_files(0); $contents = File::read($file['file'], true); foreach (explode("\n", $contents) as $line) { if (preg_match('/record [0-9]+ BAD- PHONE: ([0-9]+) ROW: \\|[0-9]+\\| DUP: [0-9] [0-9]+/i', $line, $matches)) { $all_dupes[] = $matches[1]; } } $dupe_check = \Goautodial\Insert::duplicate_check($all_dupes); foreach ($dupe_check as $dupe_number => $dupe_details) { $new_duplicate = new Model_Data_Supplier_Campaign_Lists_Duplicate(); $new_duplicate->list_id = Input::post('list_id'); $new_duplicate->database_server_id = Input::post('database_server_id'); $new_duplicate->duplicate_number = $dupe_number; $new_duplicate->dialler = $dupe_details['dialler']; $new_duplicate->lead_id = $dupe_details['data']['lead_id']; $new_duplicate->save(); } } else { print "No Uploads"; } } $this->template->title = "Data_Supplier_Campaign_Lists_Duplicates"; $this->template->content = View::forge('data/supplier/campaign/lists/duplicates/create'); }
public function action_commit() { $item = new Model_Item(); $item->name = $_POST['item_name']; $item->phonetic = $_POST['phonetic']; $item->category = $_POST['category']; if ($_POST['category'] == 'ピザ') { $item->unit_price_s = $_POST['s_money']; $item->unit_price_m = $_POST['m_money']; $item->unit_price_l = $_POST['l_money']; } else { $item->unit_price = $_POST['money']; } $item->explanatory = $_POST['explanation']; $item_img = new Model_Itemimg(); // 初期設定 $config = array('path' => DOCROOT . DS . 'assets/img', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); // アップロード基本プロセス実行 Upload::process($config); // 検証 if (Upload::is_valid()) { // 設定を元に保存 Upload::save(); $uploadfile = Upload::get_files(0); // 情報をデータベースに保存する場合 $item_img->path = $uploadfile["name"]; } foreach (Upload::get_errors() as $file) { // $file['errors']の中にエラーが入っているのでそれを処理 } $item_img->save(); $item->img_id = $item_img->id; $item->save(); return View::forge('top/top'); }
public function action_index() { $is_chenged = false; if ($this->user->bank == null) { $this->user->bank = Model_Bank::forge(); $this->user->bank->user_id = $this->user->id; $this->user->bank->save(); } if (Input::post("firstname", null) != null and Security::check_token()) { $email = Input::post("email", null); if ($email != $this->user->email) { $check_user = Model_User::find("first", ["where" => [["email" => $email]]]); if ($check_user == null) { $this->email = $email; } else { $data["error"] = "This email is already in use."; } } $config = ["path" => DOCROOT . "assets/img/pictures/", 'randomize' => true, 'auto_rename' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')]; Upload::process($config); if (Upload::is_valid()) { Upload::save(); $saved_result = Upload::get_files(); $file_name = $saved_result[0]['saved_as']; $image = Image::load($config["path"] . $file_name); $image->crop_resize(200, 200)->save($config["path"] . "m_" . $file_name); $image->crop_resize(86, 86)->save($config["path"] . "s_" . $file_name); $this->user->img_path = $file_name; } else { $error = Upload::get_errors(); } if (!isset($data["error"])) { $this->user->firstname = Input::post("firstname", ""); $this->user->middlename = Input::post("middlename", ""); $this->user->lastname = Input::post("lastname", ""); $this->user->google_account = Input::post("google_account", ""); $this->user->pr = Input::post("pr", ""); $this->user->educational_background = Input::post("educational_background", ""); $this->user->enchantJS = Input::post("enchantJS", 0); $this->user->trial = Input::post("trial", 0); $this->user->save(); $this->user->bank->name = Input::post("bank_name", ""); $this->user->bank->branch = Input::post("bank_branch", ""); $this->user->bank->account = Input::post("bank_account", ""); $this->user->bank->number = Input::post("bank_number", ""); $this->user->bank->etc = Input::post("bank_etc", ""); $this->user->bank->type = Input::post("bank_type", 0); $this->user->bank->save(); $is_chenged = true; } } $data["user"] = $this->user; $data["is_chenged"] = $is_chenged; $view = View::forge("teachers/profile", $data); $this->template->content = $view; }
public function upload() { $arrFile = array(); if ($_FILES['file_process_data']['name']) { if (\Upload::is_valid()) { \Upload::save(); $fileName = current(\Upload::get_files()); $arrFile['file_process_data'] = $fileName['saved_as']; } } return $arrFile; }
/** * Действие для редактирования данных игрока * * @param int $id */ public function action_edit($id = null) { is_null($id) and \Response::redirect_back('admin/players'); if (!($player = \Model_Player::find($id))) { \Session::set_flash('error', 'Игрок не найден.'); \Response::redirect_back('admin/players'); } $val = \Model_Player::validate('edit'); if ($val->run()) { // Валидация для фото $config = array('path' => DOCROOT . 'assets/img/players', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); \Upload::process($config); if (\Upload::is_valid() or \Upload::get_errors()[0]['errors'][0]['error'] == 4) { $player->player_name = \Input::post('player_name'); $player->is_core_player = \Input::post('is_core_player', 0); $player->position_id = \Input::post('position_id'); $player->birthdate = strtotime(\Input::post('birthdate')); $player->data = \Input::post('data'); if (!\Upload::get_errors()) { // Сохраняем файл на диск \Upload::save(); // Меняем размер изображения на 350px * 466px $files = \Upload::get_files(); $path = $files[0]['saved_to'] . $files[0]['saved_as']; \Image::load($path)->resize(350, 466, true)->save($path); // Удаляем старый файл if ($player->image_uri) { unlink(DOCROOT . 'assets/img/players/' . $player->image_uri); } $player->image_uri = $files[0]['saved_as']; } if ($player->save()) { \Session::set_flash('success', 'Игрок обновлён.'); \Response::redirect('admin/players'); } else { Session::set_flash('error', 'Could not update Player #' . $id); } } } else { if (\Input::method() == 'POST') { $player->player_name = $val->validated('player_name'); $player->is_core_player = $val->validated('is_core_player'); $player->position_id = $val->validated('position_id'); $player->birthdate = strtotime($val->validated('birthdate')); $player->data = $val->validated('data'); \Session::set_flash('error', $val->error()); } $this->template->set_global('player', $player, false); } $this->template->content = \View::forge('players/edit'); }
public function action_update($username = '******') { //バリデーション定義 $val = Validation::forge(); //ニックネームは必須で、最大文字数は50文字以内 $val->add('name', '「ニックネーム」')->add_rule('required')->add_rule('max_length', 50); //メールアドレスは必須で、入力内容がメールの形式に沿っているか $val->add('email', '「メールアドレス」')->add_rule('required')->add_rule('valid_email'); $class = Auth::get('classID'); //ログイン中の学生のレコードを取得する $user = Model_Users::find($username); //各カラムに更新情報を格納する $user->fullname = Input::post('name'); $user->email = Input::post('email'); //アップロードファイルがバリデーション通りなら投稿内容保存 if (Upload::is_valid()) { //設定を元に保存をする Upload::save(); foreach (Upload::get_files() as $file) { $user->icon = $file['saved_as']; } } if ($val->run()) { $user->save(); //更新後のレコードを取得する $this->data['users'] = Model_Users::query()->where('username', '=', $username)->get(); $this->data['classname'] = Model_Class::query()->where('classID', '=', $class)->get(); $this->action_categorise(); //ビューオブジェクトの作成 $view = View::forge('changeregistration/ChangeRegistration', $this->data); //ビューのmessage変数に更新成功時のメッセージを定義 $this->message = '登録内容を変更しました。'; //ビューに渡す変数をセットメソッドで定義する $view->set_global('message', $this->message, false); $view->set_global('error', $this->error, false); } else { //現在のレコードを取得する $this->data['users'] = Model_Users::query()->where('username', '=', $username)->get(); $this->data['classname'] = Model_Class::query()->where('classID', '=', $class)->get(); $this->action_categorise(); //バリデーションからエラーメッセージを取得する $this->error = $val->error(); //ビューオブジェクト生成 $view = View::forge('changeregistration/ChangeRegistration', $this->data); //ビューに渡す変数をセットメソッドで定義する $view->set_global('message', $this->message, false); $view->set_global('error', $this->error, false); } //ビューを返す return $view; }
/** * Действие для редактирования слайдера * * @param int $id */ public function action_edit($id = null) { is_null($id) and \Response::redirect('sliders'); if (!($slider = \Model_Slider::find($id))) { \Session::set_flash('error', 'Невозможно найти слайдер'); \Response::redirect('admin/sliders/index'); } $val = \Model_Slider::validate('edit'); if ($val->run()) { // Загружаем файл $config = array('path' => DOCROOT . 'assets/img/slider', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); \Upload::process($config); if (\Upload::is_valid()) { // Сохраняем файл на диск \Upload::save(); // Меняем размер изображения на 650px * 435px $files = \Upload::get_files(); $path = $files[0]['saved_to'] . $files[0]['saved_as']; \Image::load($path)->resize(650, 435, false)->save($path); // Удаляем старый файл unlink(DOCROOT . 'assets/img/slider/' . $slider->img_path); // Пишем инфу в БД $slider->img_path = $files[0]['saved_as']; $slider->description = \Input::post('description'); $slider->uri = \Input::post('uri'); if ($slider->save()) { \Session::set_flash('success', 'Слайд отредактировано.'); \Response::redirect('admin/sliders/index'); } else { \Session::set_flash('error', 'Ошибка при редактировании слайда.'); } } else { // Если есть ошибки при сохранении файла foreach (\Upload::get_errors() as $file) { if (isset($file['errors'][0])) { \Session::set_flash('error', $file['errors'][0]['message']); } } } } else { if (\Input::method() == 'POST') { $slider->uri = $val->validated('uri'); $slider->description = $val->validated('description'); \Session::set_flash('error', $val->error()); } } $this->template->set_global('slider', $slider, false); $this->template->title = "Слайды"; $this->template->content = \View::forge('sliders/edit'); }
public function action_add_letterhead() { $validation = Validation::forge(); if ($validation->run()) { $config = array('path' => \Subpackage\Subconfig::get(static::$_configFile . '.letterhead_directory'), 'randomize' => true, 'ext_whitelist' => array('pdf')); Upload::process($config); if (Upload::is_valid()) { Upload::save(); $filename = Upload::get_files(); $insertID = Model_Letterhead::create(Input::post('letterhead_title'), Input::post('letterhead_description'), Input::post('letterhead_company'), $filename[0]['saved_as'], array('top' => Input::post('letterhead_margin_top'), 'bottom' => Input::post('letterhead_margin_bottom'), 'left' => Input::post('letterhead_margin_left'), 'right' => Input::post('letterhead_margin_right')), Input::post('letterhead_product')); print "Added Letterhead with ID: " . $insertID; } } $this->template->title = 'Add Letterhead : Letter Management'; $this->template->content = View::forge(static::$_viewPath . 'manage/add_letterhead.php', array('companies' => \Crm\Company\Company_model::companyList())); }
public function action_update($Pid = 0) { $username = Auth::get_screen_name(); $this->data['token_key'] = Config::get('security.csrf_token_key'); $this->data['token'] = Security::fetch_token(); if (Security::check_token()) { $val = Model_Post::validate(); if ($val->run()) { $post = Model_Post::find($Pid); $post->class = Input::post('cla'); $post->Title = Input::post('title'); $post->Pcontent = Input::post('Pcontent'); $post->Kid = Input::post('category'); Upload::process(); if (Upload::is_valid()) { //設定を元に保存をする Upload::save(); foreach (Upload::get_files() as $file) { $post->image = $file['saved_as']; } } $post->save(); $this->action_categorize(); $this->data['users'] = Model_Users::query()->where('username', '=', $username)->get(); $this->data['posts'] = Model_Post::query()->where('username', '=', $username)->order_by('Ptime', 'desc')->get(); $message = '投稿内容を変更しました。'; $view = View::forge('mypage/mypage', $this->data); $view->username = $username; $view->set_global('message', $message, false); $view->set_global('error', $this->error, false); //バリデーションエラー } else { $this->action_categorize(); $Pid and $this->data['posts'] = DB::select()->from('Post')->where('Pid', '=', $Pid)->execute(); $view = View::forge('post/PostEdit', $this->data); $this->error = $val->error(); $view->username = $username; $view->set_global('error', $this->error, false); } } else { Profiler::mark('CSRFだー!'); } return $view; }
/** * Редактирование команды * * @param int $id */ public function action_edit($id = null) { is_null($id) and \Response::redirect('teams'); if (!($team = \Model_Team::find($id))) { \Session::set_flash('error', 'Команда не найдена.'); \Response::redirect_back('admin/competitions/teams'); } $val = \Model_Team::validate('edit'); if ($val->run()) { // Валидация для фото $config = array('path' => DOCROOT . 'assets/img/teams', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); \Upload::process($config); if (\Upload::is_valid() or \Upload::get_errors()[0]['errors'][0]['error'] == 4) { $team->value = \Input::post('value'); if (!\Upload::get_errors()) { // Сохраняем файл на диск \Upload::save(); // Меняем размер изображения на 50px * 50px $files = \Upload::get_files(); $path = $files[0]['saved_to'] . $files[0]['saved_as']; \Image::load($path)->resize(50, 50, true)->save($path); // Удаляем старый файл if ($team->logo_uri) { unlink(DOCROOT . 'assets/img/teams/' . $team->logo_uri); } $team->logo_uri = $files[0]['saved_as']; } if ($team->save()) { \Session::set_flash('success', 'Команда обновлена.'); \Response::redirect_back('admin/competitions/teams'); } else { Session::set_flash('error', 'Could not update Team #' . $id); } } } else { if (\Input::method() == 'POST') { $team->value = $val->validated('value'); \Session::set_flash('error', $val->error()); } $this->template->set_global('team', $team, false); } $this->template->content = \View::forge('competitions/teams/edit'); }
public function action_upload($folder, $sub = null) { if (\Fuel\Core\Input::method() == 'POST') { try { \Fuel\Core\DB::start_transaction(); $val = Model_Filemanager::validate('create'); if ($val->run()) { $config = array('path' => "/var/www/html/" . $this->_dir . "/" . $folder . "/" . $sub . DS, 'ext_whitelist' => array('jpg', 'jpeg', 'png'), 'file_chmod' => 0777, 'auto_rename' => true, 'overwrite' => true, 'randomize' => true, 'create_path' => true); Upload::process($config); $img = ''; if (Upload::is_valid()) { Upload::save(); $img = Upload::get_files()[0]; } if (!\Fuel\Core\Input::post('id')) { $file = Model_Filemanager::forge(array('folder' => $folder, 'key' => Input::post('key'), 'value' => $img['saved_as'], 'photographer' => \Fuel\Core\Input::post('photographer'), 'price' => \Fuel\Core\Input::post('price'), 'usage' => \Fuel\Core\Input::post('usage'), 'source' => \Fuel\Core\Input::post('source'))); } else { $file = Model_Filemanager::find_by_id(\Fuel\Core\Input::post('id')); if ($img == '') { $img = $file->value; } if ($file) { $file->set(array('folder' => $folder, 'key' => Input::post('key'), 'value' => $img, 'photographer' => \Fuel\Core\Input::post('photographer'), 'price' => \Fuel\Core\Input::post('price'), 'usage' => \Fuel\Core\Input::post('usage'), 'source' => \Fuel\Core\Input::post('source'))); } else { throw new Exception('File not found!'); } } if ($file and $file->save()) { DB::commit_transaction(); \Fuel\Core\Session::set_flash('success', 'Upload success'); } else { throw new Exception('Cannot save into database!'); } } else { throw new Exception($val->show_errors()); } } catch (Exception $e) { DB::rollback_transaction(); \Fuel\Core\Session::set_flash('error', $e->getMessage()); } } \Fuel\Core\Response::redirect(\Fuel\Core\Uri::create('filemanager/folder/' . $folder)); }
public function action_do_upload() { logger('1', 'Starting upload'); \Upload::process(array('path' => './uploads', 'normalize' => true, 'change_case' => 'lower')); logger('1', 'Finished upload'); echo "<pre>"; print_r(\Upload::get_files()); print_r(\Upload::get_errors()); logger('1', 'Errors: ' . serialize(\Upload::get_errors())); echo \Upload::is_valid() ? "<span style='color: green; font-weight: bold;'>VALID</span>" : "<span style='color: red; font-weight: bold;'>ERROR</span>"; echo '<br><br><br>'; \Upload::save(); echo 'Valid:<br>'; print_r(\Upload::get_files()); logger('1', 'Valid uploads: ' . serialize(\Upload::get_files())); echo '<br>Errors:<br>'; print_r(\Upload::get_errors()); echo "</pre>"; }
public function action_register() { if (Input::method() == 'POST') { $val = Model_User::validate('create'); if ($val->run()) { $user = Model_User::forge(array('username' => Input::post('username'), 'password' => Auth::instance()->hash_password(Input::post('password')), 'group' => 1, 'email' => Input::post('email'), 'fname' => Input::post('fname'), 'mname' => Input::post('mname'), 'lname' => Input::post('lname'), 'contact_num' => Input::post('contact_num'), 'address' => Input::post('address'), 'profile_pic' => Input::post('profile_pic'), 'last_login' => Input::post('last_login'), 'login_hash' => Input::post('login_hash'), 'profile_fields' => Input::post('profile_fields'))); Upload::process(Config::get('upload_profile_picture')); $user->profile = Model_Student::forge(['year_level' => 0, 'course_id' => 0]); if (Upload::is_valid()) { Upload::save(); $value = Upload::get_files(); foreach ($value as $files) { $user->profile_pic = $value[0]['saved_as']; } if ($user and $user->save()) { Session::set_flash('success', e('Succesfully Added user #' . $user->id . '.')); Response::redirect('site/login'); } else { Session::set_flash('error', e('Could not save user.')); } } else { Session::set_flash('error', e('Uploaded photo is invalid.')); } // if ($user and $user->save()) // { // Session::set_flash('success', e('Succesfully Added user #'.$user->id.'.')); // Response::redirect('site/login'); // } // else // { // Session::set_flash('error', e('Could not save user.')); // } } else { Session::set_flash('error', $val->error()); } } // $this->template->title = "Users"; // $this->template->content = View::forge('admin/users/create'); $this->template->title = 'Register'; $this->template->content = View::forge('site/register'); }
public function action_index() { $is_chenged = false; if (Input::post("firstname", null) != null and Security::check_token()) { $email = Input::post("email", null); if ($email != $this->user->email) { $check_user = Model_User::find("first", ["where" => [["email" => $email]]]); if ($check_user == null) { $this->email = $email; } else { $data["error"] = "This email is already in use."; } } $config = ["path" => DOCROOT . "assets/img/pictures/", 'randomize' => true, 'auto_rename' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')]; Upload::process($config); if (Upload::is_valid()) { Upload::save(); $saved_result = Upload::get_files(); $file_name = $saved_result[0]['saved_as']; $image = Image::load($config["path"] . $file_name); $image->crop_resize(200, 200)->save($config["path"] . "m_" . $file_name); $image->crop_resize(86, 86)->save($config["path"] . "s_" . $file_name); $this->user->img_path = $file_name; } else { $error = Upload::get_errors(); } if (!isset($data["error"])) { $this->user->firstname = Input::post("firstname", ""); $this->user->middlename = Input::post("middlename", ""); $this->user->lastname = Input::post("lastname", ""); $this->user->save(); $is_chenged = true; } } $data['pasts'] = Model_Lessontime::find("all", ["where" => [["student_id", $this->user->id], ["status", 2], ["language", Input::get("course", 0)], ["deleted_at", 0]]]); $data["donetrial"] = Model_Lessontime::find("all", ["where" => [["student_id", $this->user->id], ["status", 2], ["language", Input::get("course", -1)], ["deleted_at", 0]]]); $data["user"] = $this->user; $data["is_chenged"] = $is_chenged; $view = View::forge("students/profile", $data); $this->template->content = $view; }
public function action_file($table_name) { // Find class name and metadata etc $class_name = \Admin::getClassForTable($table_name); if ($class_name === false) { return $this->show404(null, "type"); } // Don't continue if no files have been uploaded if (!count(\Upload::get_files())) { \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-danger'), 'msg' => \Lang::get('admin.errors.upload.no_files'))); \Response::redirect_back("/admin/{$table_name}"); } // Ensure directory exists $path = DOCROOT . 'uploads/imports'; if (!is_dir($path)) { @mkdir($path, 0775, true); } if (!is_dir($path)) { \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-danger'), 'msg' => \Lang::get('admin.errors.upload.directory_not_created'))); return; } // Process the uploaded file \Upload::process(array('path' => $path, 'auto_rename' => false, 'overwrite' => true, 'normalize' => true, 'ext_whitelist' => array('xlsx', 'xls', 'xml', 'csv', 'json'))); // Save it to the filesystem if valid if (\Upload::is_valid()) { \Upload::save(); } // Import the file $file = \Upload::get_files(0); $file_path = \Arr::get($file, 'saved_to') . \Arr::get($file, 'saved_as'); $this->import_result = \CMF\Utils\Importer::importFile($file_path, $class_name); // If success, redirect back with message if (isset($this->import_result['success']) && $this->import_result['success']) { \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.messages.import_success'))); \Response::redirect("/admin/{$table_name}", 'location'); } // No success, damn! \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-danger'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.errors.actions.import'))); \Response::redirect_back("/admin/{$table_name}"); }
public function action_base64_encode_image() { if ($_POST) { $asciiFormat = Inflector::ascii(Input::post('filename')); $webSafeName = Inflector::friendly_title($asciiFormat, '_', true); $uploadLocation = 'assets/img/upload/'; $config = array('auto_process' => 'false', 'path' => DOCROOT . $uploadLocation, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'), 'new_name' => $webSafeName, 'normalize' => true, 'change_case' => 'lower', 'auto_rename' => false, 'overwrite' => true); // process the uploaded files in $_FILES Upload::process($config); // if there are any valid files if (Upload::is_valid()) { // save them according to the config Upload::save(); // Grab the file extension $uploadedFile = Upload::get_files(0); $filename = $webSafeName . '.' . $uploadedFile['extension']; $input_file = $uploadedFile['saved_to'] . $uploadedFile['saved_as']; $image64Encoded = $this->_base64_encode_image($input_file, $uploadedFile['extension']); $asset = Model_Asset::forge(array('name' => $uploadedFile['saved_as'], 'uri' => $uploadLocation, 'type' => $uploadedFile['extension'])); $asset->save(); return '<img src="' . $image64Encoded . '" />'; } else { // and process any errors foreach (Upload::get_errors() as $key => $file) { // $file is an array with all file information, // $file['errors'] contains an array of all error occurred // each array element is an an array containing 'error' and 'message' // Session::set_flash('error', $file['errors'] ); echo 'Error ' . $key . ' - '; print_r($file['errors']); echo ' <br />'; } die; } } return; }
public function action_create() { try { if (Input::method() == 'POST') { $file = Input::file('news_photo_file'); $val = Model_News::validate('create'); if ($val->run()) { $config = array('path' => "/var/www/html/uploads/news_photo/", 'ext_whitelist' => array('jpg', 'jpeg', 'png'), 'file_chmod' => 0777, 'auto_rename' => true, 'overwrite' => true, 'randomize' => true, 'create_path' => true); // $allowList = array(".jpeg", ".jpg", ".png"); // $error = false; // $path = realpath(DOCROOT."/../../uploads/news_photo/").DS; $news_photo = ""; Upload::process($config); if (Upload::is_valid()) { Upload::save(); $news_photo = Upload::get_files()[0]; $news = Model_News::forge(array('news_title' => Input::post('news_title'), 'news_short_detail' => Input::post('news_short_detail'), 'news_detail' => Input::post('news_detail'), 'news_photo' => $news_photo['saved_as'], 'news_published' => Input::post('news_published'), 'created_at' => time(), 'published_at' => Input::post('news_published') == 1 ? time() : 0)); if ($news and $news->save()) { Session::set_flash('success', 'Added news #' . $news->id . '.'); Response::redirect('news/edit/' . $news->id); } else { Session::set_flash('error', 'Could not save news.'); } if ($file and $file->save()) { DB::commit_transaction(); \Fuel\Core\Session::set_flash('success', 'Upload success'); } } /*if($file['size'] > 0){ $ext = strtolower(substr($file['name'],strrpos($file['name'],"."))); if(!in_array($ext,$allowList)){ Session::set_flash('error', 'ชนิดของไฟล์ภาพไม่ถูกต้อง'); $error = true; } $filename = md5(time()); if(@copy($file['tmp_name'],$path.$filename.$ext)){ $news_photo = $filename.$ext; /* small thumbnail */ # parent::create_cropped_thumbnail($path.$filename.$ext,64,64,"-s"); # parent::create_cropped_thumbnail($path.$filename.$ext,128,128,"-s@2x"); /* */ /* medium thumbnail */ # parent::create_cropped_thumbnail($path.$filename.$ext,360,240,"-m"); # parent::create_cropped_thumbnail($path.$filename.$ext,720,480,"-m@2x"); /* } else { Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ภาพได้ โปรดลองใหม่อีกครั้ง'); $error = true; } }*/ /*if(!$error){ $news = Model_News::forge(array( 'news_title' => Input::post('news_title'), 'news_short_detail' => Input::post('news_short_detail'), 'news_detail' => Input::post('news_detail'), 'news_photo' => $news_photo, 'news_published' => Input::post('news_published'), 'created_at' => time(), 'published_at' => (Input::post('news_published')==1)?time():0 )); if ($news and $news->save()){ Session::set_flash('success', 'Added news #' . $news->id . '.'); Response::redirect('news/edit/'.$news->id); } else { Session::set_flash('error', 'Could not save news.'); } }*/ } else { $msg = '<ul>'; foreach ($val->error() as $field => $error) { $msg .= '<li>' . $error->get_message() . '</li>'; } $msg .= '</ul>'; Session::set_flash('error', $msg); } } $this->theme->set_template('edit'); $this->theme->get_template()->set_global('current_menu', "News", false); $this->theme->get_template()->set_global('current_menu_desc', "จัดการข่าวทั้งหมดในระบบ", false); $this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "News", 'icon' => "eicon-newspaper", 'link' => Uri::create('news/index'), 'active' => false), array('title' => "Create", 'icon' => "", 'link' => "", 'active' => true))); $this->theme->get_template()->set_global('mode', "create", false); $this->theme->get_template()->set('page_specific_js', "form_news.js"); $this->theme->set_partial('sidebar', 'common/sidebar'); $this->theme->set_partial('left', 'news/create'); } catch (Exception $e) { die($e->getMessage()); } }
/** * Upload all infotab images to local directory defined in $this->image_upload_config * * @param $content_type = Content type to pull config from (Image, Video) * */ public function upload_infotab_image($content_type = 'image') { $return['is_valid'] = true; $return['exists'] = false; $return['errors'] = false; // Check if there are selected files foreach (\Input::file() as $file) { if ($file['name'] != '') { $return['exists'] = true; } } // No files selected, so no errors too if (!$return['exists']) { return $return; } // Image upload configuration $this->infotab_image_upload_config = array('path' => \Config::get('infotab.' . $content_type . '.location.root'), 'normalize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); \Upload::process($this->infotab_image_upload_config); // if there are any valid files if (\Upload::is_valid()) { // Save image \Upload::save(); $this->_infotab_image_data = \Upload::get_files(); // Resize images to desired dimensions defined in config file try { foreach ($this->_infotab_image_data as $image_data) { $image = \Image::forge(array('presets' => \Config::get('infotab.' . $content_type . '.resize', array()))); $image->load($image_data['saved_to'] . $image_data['saved_as']); foreach (\Config::get('infotab.' . $content_type . '.resize', array()) as $preset => $options) { $image->preset($preset); } } return $return; } catch (\Exception $e) { $return['is_valid'] = false; $return['errors'][] = $e->getMessage(); } } else { // IMAGE ERRORS if (\Upload::get_errors() !== array()) { foreach (\Upload::get_errors() as $file) { foreach ($file['errors'] as $key => $value) { $return['is_valid'] = false; $return['errors'][] = $value['message']; } } } } // If we got up to here, image is not uploaded return $return; }
public function action_upload($id) { if (Input::method() == 'POST') { $config = array('path' => '/var/www/html/www.ameken.com/fuel_addbook/public/assets/img/collection', 'auto_rename' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); // print_r($config); exit; Upload::process($config); if (Upload::is_valid()) { Upload::save(); $result = Upload::get_files(); $colimage = Model_Colimage::forge(); $colimage->filename = $result[0]['saved_as']; $colimage->mimetype = $result[0]['mimetype']; $colimage->filepath = 'collection/' . $result[0]['saved_as']; $colimage->collection_id = $id; // var_dump($colimage); exit; $colimage->info = serialize($result[0]); if ($colimage and $colimage->save()) { Session::set_flash('success', '<span class="btn btn-primary span9">ID-' . $colimage->collection_id . 'の「' . $colimage->filename . '」を追加しました</span><br>'); Response::redirect("collection/detail/{$id}"); } else { Session::set_flash('error', '保存できませんでした'); } } } $data['col'] = Model_Collection::find($id); $this->template->content = View::forge('collection/upload', $data); }
/** * Действие для редактирования фотографии * * @param int $id */ public function action_edit($id = null) { is_null($id) and \Response::redirect('admin/media/photos/categories'); if (!($photo = \Model_Media_Photo::find($id, array('related' => 'category')))) { \Session::set_flash('error', 'Фотография не найдена.'); \Response::redirect('admin/media/photos/categories'); } $val = \Model_Media_Photo::validate('edit'); if ($val->run()) { // Загружаем файл $config = array('path' => DOCROOT . 'assets/img/gallery', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); \Upload::process($config); if (\Upload::is_valid()) { // Сохраняем файл на диск \Upload::save(); // Меняем размер изображения на 1024px * 768px $files = \Upload::get_files(); $path = $files[0]['saved_to'] . $files[0]['saved_as']; \Image::load($path)->resize(1024, 768, true)->save($path); // Создаём thumbnail $thumb_path = $files[0]['saved_to'] . 'thumbnails/' . $files[0]['saved_as']; \Image::load($path)->resize(400, 300, true)->save($thumb_path); // Удаляем старые файлы unlink(DOCROOT . 'assets/img/gallery/' . $photo->image_path); unlink(DOCROOT . 'assets/img/gallery/thumbnails/' . $photo->image_path); // Пишем инфу в БД $photo->image_path = $files[0]['saved_as']; if ($photo->save()) { \Session::set_flash('success', 'Фотография обновлена.'); \Response::redirect('admin/media/photos/list/index/' . $photo->category->id); } else { \Session::set_flash('error', 'Could not update Media_Photo #' . $id); } } } else { if (\Input::method() == 'POST') { \Session::set_flash('error', $val->error()); } $this->template->set_global('photo', $photo, false); } $this->template->title = 'Фотогалерея "' . $photo->category->title . '"'; $this->template->content = \View::forge('media/photos/list/edit'); }
/** * Upload all contet files to local directory defined in $this->file_upload_config * */ public function upload_file() { $return['is_valid'] = true; $return['exists'] = false; $return['errors'] = false; // Check if there are selected files foreach (\Input::file() as $file) { if ($file['name'] != '') { $return['exists'] = true; } } // No files selected, so no errors too if (!$return['exists']) { return $return; } // File upload configuration $this->file_upload_config = array('path' => \Config::get('details.file.location.root'), 'normalize' => true, 'ext_whitelist' => array('pdf', 'xls', 'xlsx', 'doc', 'docx', 'txt')); \Upload::process($this->file_upload_config); // if there are any valid files if (\Upload::is_valid()) { // Save file \Upload::save(); $this->_file_data = \Upload::get_files(); return $return; } else { // FILE ERRORS if (\Upload::get_errors() !== array()) { foreach (\Upload::get_errors() as $file) { foreach ($file['errors'] as $key => $value) { $return['is_valid'] = false; $return['errors'][] = $value['message']; } } } } // If we got up to here, file is not uploaded return $return; }
public function action_change() { $uid = $this->viewer_info['uid']; $uname = $this->viewer_info['name']; $data = array(); if (isset($_POST['ch_name'])) { //ユーザ名変更を試みる //Validationオブジェクト生成 $val = Validation::forge(); //フォームのルール設定 $val->add('uname', 'ユーザ名')->add_rule('valid_string', array('alpha', 'numeric', 'dashes', 'dots', 'punctuation', 'utf8')); //Validationチェック if ($val->run()) { $newname = Input::post('uname'); $data['newname'] = $newname; Model_Members_General2::setUname($uid, $newname); $uname = $newname; } //Validationオブジェクトをviewに渡す $data['val'] = $val; } if (isset($_POST['ch_image'])) { //アイコン画像変更を試みる if (Input::file('upload.name')) { //アップロードされてるか //アップロード用初期設定 $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); //アップロード基本プロセス Upload::process($config); //検証 if (Upload::is_valid()) { //設定を元に保存 Upload::save(); //保存されたファイル名を変数に入れる $getfile = Upload::get_files(); $upload_file = $getfile[0]['name']; } else { //ファイルがアップロードできなかったとき、 //エラーメッセージをセット $upload_err = 'ファイルが正しくアップできませんでした。'; $data['upload_err'] = $upload_err; $this->template = View::forge('members/userpg/userpg_myself_template'); $this->template->title = "旅ログ - " . $uname . "さんのユーザ情報変更"; $this->template->username = $uname; $this->template->icon = Model_Members_Userinfo::getIcon($uid); $this->template->uid = $uid; $this->template->pagename = $uname . "さんのユーザ情報変更"; $this->template->page_num = 5; $data['name'] = $uid; $data['pagename'] = $uname . "さんのユーザ情報変更"; $data['info'] = Model_Members_Userinfo::getInfo($uid); $this->template->content = View::forge('members/userpg/change', $data); return; //var_dump($upload_err); exit; } //データベースに保存 Model_Members_General2::setProfile($uname, $upload_file); } } $this->template = View::forge('members/userpg/userpg_myself_template'); $this->template->title = "旅ログ - " . $uname . "さんのユーザ情報変更"; $this->template->username = $uname; $this->template->icon = Model_Members_Userinfo::getIcon($uid); $this->template->uid = $uid; $this->template->pagename = $uname . "さんのユーザ情報変更"; $this->template->page_num = 5; $data['name'] = $uid; $data['pagename'] = $uname . "さんのユーザ情報変更"; $data['info'] = Model_Members_Userinfo::getInfo($uid); $this->template->content = View::forge('members/userpg/change', $data); }
public function action_index() { //Model_Postオブジェクトを新規作成 $post = Model_Post::forge(); $post->user_id = 1; //県のセレクト用のオプション配列の作成 $prefectures = Model_Prefecture::find('all'); $pref_op = array(); foreach ($prefectures as $pref) { $pref_op[$pref->id] = $pref->name; } //カテゴリのチェックボックス用のオプション配列の作成 $categories = array('何かを学ぶ旅' => '何かを学ぶ旅', '温泉でゆったりする旅' => '温泉でゆったりする旅', 'テーマパーク・アミューズメントの旅' => 'テーマパーク・アミューズメントの旅', '大自然にふれる旅' => '大自然にふれる旅', '街並みを楽しむ旅' => '街並みを楽しむ旅', 'グルメな旅' => 'グルメな旅', '平和について考える旅' => '平和について考える旅'); //タグのチェックボックス用のオプション配列の作成 $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); //Fieldsetオブジェクトにモデルを登録 $fieldset = Fieldset::forge('fset', $config)->add_model('Model_Post'); //県名選択を登録 $fieldset->add_before('prefid', '県名', array('type' => 'select', 'options' => $pref_op), array('required', 'in_array' => $pref_op), 'place'); //カテゴリ選択を登録 $fieldset->add_before('category2', 'カテゴリ', array('type' => 'select', 'options' => $categories), array('required', 'in_array' => $categories), 'tag1'); //ファイルアップロードを登録 $fieldset->add_after('imagefile', '写真', array('type' => 'file'), array('required'), 'rating'); //$fieldset->field('imagefile')->set_attribute('form_attributes',array('enctype'=>'multipart/form-data')); //投稿ボタンを登録 $fieldset->add_after('submit', '', array('type' => 'submit', 'value' => '投稿'), array(), 'rating'); //モデルの値をFieldsetに登録 $fieldset->populate($post, true); //$form = $fieldset->form(); //$form['imagefile']->set_config('form_attributes', array('enctype'=>'multipart/form-data')); //POSTの場合は登録処理を行う if (Input::method() == 'POST') { //Validationの実行 if ($fieldset->validation()->run()) { if (Input::post('imagefile')) { Upload::process($config); if (Upload::is_valid()) { Upload::save(); $getfile = Upload::get_files(); $file = $getfile[0]['name']; } else { //ファイルがアップロードできなかったとき、メッセージをフラッシュセッションにセット Session::set_flash('uerr', 'ファイルが正しくアップできませんでした。'); //投稿を中断して入力画面へリダイレクト Response::redirect('members/postfieldset'); } } var_dump($file); exit; //Validationに成功したフィールドの読み込み $fields = $fieldset->validated(); //Model_Postオブジェクトの生成 $post = Model_Post::forge(); //Model_Postオブジェクトのプロパティの設定 $post->user_id = $fields['user_id']; $post->pref_id = $fields['prefid']; $post->place = $fields['place']; $post->title = $fields['title']; $post->content = $fields['content']; $post->category = $fields['category2']; $post->tag1 = $fields['tag1']; $post->tag2 = $fields['tag2']; $post->rating = $fields['rating']; $post->image = $file; if ($post->save()) { Response::redirect('members/top'); } else { //入力エラーがある場合は元の入力画面にもどるため //入力した内容をそのまま引き継ぐ $fieldset->repopulate(); } } } //ビューの生成とbuild()したHTMLの埋め込み /* 本当は、members/postlist に飛びたい */ $view = View::forge('members/postfieldset'); $view->set('form', $fieldset->build(), false); return Response::forge($view); }
/** * ファイルアップロード<br> * 失敗した場合はfalseを返します。 */ private static function file_upload($shop_id) { if (is_null($shop_id)) { Log::error("parameter's shpo_id is null."); return false; } # ファイルアップロード設定 $config = self::file_upload_config($shop_id); # アップロード実行 Upload::process($config); # 検証 if (Upload::is_valid()) { # アップロードファイルを保存(最初の1つを指定) Upload::save(0); foreach (Upload::get_files() as $file) { return $file['saved_as']; } } # エラー有り foreach (Upload::get_errors() as $file) { foreach ($file['errors'] as $error) { Log::error("file upload is fail. => {$error}", "file_upload"); } } return false; }
public function action_discuss_brief() { if (\Input::post()) { // check for a valid CSRF token if (!\Security::check_token()) { \Messages::error('CSRF attack or expired CSRF token.'); \Response::redirect(\Input::referrer(\Uri::create('/'))); } $file = null; // Send autoresponder $autoresponder = \Autoresponder\Autoresponder::forge(); $autoresponder->view_custom = 'discuss_brief'; $autoresponder->view_admin = 'discuss_brief'; $post = \Input::post(); if ($product = \Product\Model_Product::find_one_by_id(\Input::post('product'))) { $post['product'] = $product; } $content['content'] = $post; $config = array('path' => APPPATH . 'tmp', 'normalize' => true, 'max_size' => 5242880); // Check if file uploaded if (isset($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['name'] != '') { // process the uploaded files in $_FILES \Upload::process($config); // if there are any valid files if (\Upload::is_valid()) { // save them according to the config \Upload::save(); $file = \Upload::get_files(0); } // Upload errors if (\Upload::get_errors() !== array()) { foreach (\Upload::get_errors() as $file) { foreach ($file['errors'] as $key => $value) { \Messages::error($value['message']); } } \Response::redirect(\Input::referrer(\Uri::create('/'))); } } $attachment = array(); if (isset($file['saved_to']) && is_file($file['saved_to'] . $file['saved_as'])) { $attachment = array($file['saved_to'] . $file['saved_as']); } // echo 'test'; // die; $content['subject'] = 'Thanks for contacting Evan Evans'; $autoresponder->autoresponder_custom($content, \Input::post('email'), $attachment); $content['subject'] = 'Autoresponder Discuss Brief for Admin'; $autoresponder->autoresponder_admin($content, \Config::get('auto_response_emails.discuss_brief'), $attachment); if ($autoresponder->send()) { \Messages::success('Thank You for sending request.'); } else { \Messages::error('There was an error while trying to submit request.'); } // Delete uploaded files if (!empty($attachment)) { foreach ($attachment as $file) { if (is_file($file)) { unlink($file); } } } \Response::redirect(\Input::referrer(\Uri::create('/'))); } if (\Input::is_ajax()) { $products = \Product\Model_Product::fetch_pair('id', 'title', array('order_by' => array('title' => 'asc'))); echo \Theme::instance()->view('views/_partials/discuss_brief')->set('products', $products, false); exit; } throw new \HttpNotFoundException(); }
public function action_index() { //ビューに渡すデータの配列を初期化 $data = array(); //県のセレクト用のオプション配列の作成 $prefectures = Model_Prefecture::find('all'); $pref_op = array(); foreach ($prefectures as $pref) { $pref_op[$pref->id] = $pref->name; } $data['prefs'] = $pref_op; //カテゴリのチェックボックス用のオプション配列の作成 $catego_op = array('何かを学ぶ旅' => '何かを学ぶ旅', '温泉でゆったりする旅' => '温泉でゆったりする旅', 'テーマパーク・アミューズメントの旅' => 'テーマパーク・アミューズメントの旅', '大自然にふれる旅' => '大自然にふれる旅', '街並みを楽しむ旅' => '街並みを楽しむ旅', 'グルメな旅' => 'グルメな旅', '平和について考える旅' => '平和について考える旅'); $data['categories'] = $catego_op; //入力チェックのためのvalidationオブジェクトを呼び出す $val = Validation::forge(); // $val->add('pref', '県名')->add_rule('required'); $val->add('place', '場所')->add_rule('required'); $val->add('title', 'タイトル')->add_rule('required'); $val->add('content', '記事内容')->add_rule('required'); $val->add('category', 'カテゴリ')->add_rule('required'); $val->add('tag1', 'タグ1')->add_rule('required'); $val->add('tag2', 'タグ2')->add_rule('required'); $val->add('rating', '評価')->add_rule('required'); //validationチェック if ($val->run()) { /*----------- 画像ファイルの入力があったらアップロード ---------------*/ //データ保存用変数 初期化 $upload_file = ''; if (Input::file('upload.name')) { //アップロード用初期設定 $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); //アップロード基本プロセス Upload::process($config); //検証 if (Upload::is_valid()) { //設定を元に保存 Upload::save(); //保存されたファイル名を変数に入れる $getfile = Upload::get_files(); $upload_file = $getfile[0]['name']; } else { //ファイルがアップロードできなかったとき、メッセージをフラッシュセッションにセット Session::set_flash('uerr', 'ファイルが正しくアップできませんでした。'); //投稿を中断して入力画面へリダイレクト Response::redirect('members/post2'); } } /*------ postされた各データをDBに保存 ----------*/ if ($upload_file == '') { Session::set_flash('uerr', 'ファイルを選択してください。'); //投稿を中断して入力画面へリダイレクト Response::redirect('members/post2'); } //各送信データを配列 $props = array('user_id' => 1, 'pref_id' => Input::post('pref'), 'place' => Input::post('place'), 'title' => Input::post('title'), 'content' => Input::post('content'), 'category' => Input::post('category'), 'tag1' => Input::post('tag1'), 'tag2' => Input::post('tag2'), 'rating' => Input::post('rating'), 'image' => $upload_file); //モデルオブジェクト作成 $new = Model_Post::forge($props); //データを保存する if (!$new->save()) { //保存失敗 $data['save'] = '正しく投稿できませんでした。'; } else { //保存成功 $data['save'] = '投稿されました。'; } } //$val->run()ここまで //validationオブジェクトをviewに渡す $data['val'] = $val; /*--------------- 投稿済みのデータをDBから取得 -------------*/ /*$data['posts'] = Model_Post::find('all', array( 'order_by' => array( 'created_at' => 'desc' )));*/ return View::forge('members/post2', $data); }
protected function get_upload_file($config) { try { Upload::process($config); } catch (Exception $e) { return null; // 未ログイン = アップロードなし = なにもしない } if (!Upload::is_valid()) { $files = Upload::get_errors(); foreach ($files as $f) { foreach ($f['errors'] as $e) { if ($e['error'] == 4) { // no upload continue; } else { $this->set_error([$f['field'] => 'ファイル形式が不正です'], true); } } } if ($this->has_error()) { return false; } } return Upload::get_files(); }