本文整理汇总了PHP中Upload::is_valid方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::is_valid方法的具体用法?PHP Upload::is_valid怎么用?PHP Upload::is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Upload
的用法示例。
在下文中一共展示了Upload::is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post_parse_payments
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";
}
}
示例2: moveUploadedFile
/**
* アップロードファイルを指定のフォルダに移動する
*
* @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);
}
示例3: action_register
/**
* 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;
}
示例4: action_create
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');
}
示例5: action_commit
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');
}
示例6: action_index
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;
}
示例7: upload
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;
}
示例8: action_edit
/**
* Действие для редактирования данных игрока
*
* @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');
}
示例9: action_update
public function action_update($username = 'k000c0000')
{
//バリデーション定義
$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;
}
示例10: action_edit
/**
* Действие для редактирования слайдера
*
* @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');
}
示例11: action_add_letterhead
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()));
}
示例12: action_update
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;
}
示例13: action_edit
/**
* Редактирование команды
*
* @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');
}
示例14: action_upload
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));
}
示例15: action_do_upload
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>";
}