本文整理汇总了PHP中Upload::process方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::process方法的具体用法?PHP Upload::process怎么用?PHP Upload::process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Upload
的用法示例。
在下文中一共展示了Upload::process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* upload files
*/
protected function create($model, $form)
{
// check rights
if (!Acl::instance()->allowed($this->_controller, 'create')) {
throw HTTP_Exception::factory(403, 'Create not allowed on :controller', array(':controller' => $this->_controller));
}
$hash = FALSE;
Event::raise($this, Event::BEFORE_CREATE_FORM_PARSE, array('model' => NULL, 'form' => $form));
if ($form->valid()) {
$hash = Upload::process('file', $this->_settings->get('path_temp'), $this->_settings->get('extensions'), $this->_settings->get('unzip'));
}
if ($hash !== FALSE) {
return $hash;
} else {
if ($form->submitted()) {
// set error in form
$form->element('file', 0)->error('not_empty');
}
// create viewer
$viewer = Viewer::factory('Form', $form)->text(Text::instance());
// render form
$view = View::factory($this->_settings->get('view.create'), array('viewer' => $viewer));
// event
Event::raise($this, Event::BEFORE_CREATE_RENDER, array('model' => NULL, 'form' => $form, 'viewer' => $viewer, 'view' => $view));
// render
$this->response->body($view->render());
return FALSE;
}
}
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:32,代码来源:File.php
示例2: beforeSave
function beforeSave()
{
if (!$this->isFolder()) {
# se guarda el archivo original
$path = WWW_ROOT . Configure::read("Media.Upload.dir") . $this->data['Upload']['path'];
//$this->data['Upload']['name']=$this->Uploader->file_dst_name_body;
//$this->Uploader->file_dst_name_body=Inflector::slug($this->Uploader->file_src_name_body);
$this->Uploader->process($path);
$num = str_replace(str_replace(' ', '_', $this->data['Upload']['name']), "", $this->Uploader->file_dst_name_body);
if ($num) {
$this->data['Upload']['name'] .= "{$num}";
}
if (!$this->isFolder() && $this->isImage()) {
# se crea la miniatura
$this->copy(array('width' => 100, 'height' => 100), $path, 'thumb_' . $this->data['Upload']['name']);
# se guarda la foto grande
if ($this->data['Upload']['width'] >= 1200) {
$width = 1024;
$height = round($width / $this->data['Upload']['width'] * $this->data['Upload']['height']);
$this->copy(array('width' => $width, 'height' => $height), $path, $width . "x" . $height . "_" . $this->data['Upload']['name']);
}
# se guarda la foto mediana
if ($this->data['Upload']['width'] >= 400) {
$width = 300;
$height = round($width / $this->data['Upload']['width'] * $this->data['Upload']['height']);
$this->copy(array('width' => $width, 'height' => $height), $path, $width . "x" . $height . "_" . $this->data['Upload']['name']);
}
}
}
return true;
}
示例3: 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";
}
}
示例4: store
/**
* Stores new upload
*
*/
public function store()
{
$file = Input::file('file');
$upload = new Upload();
try {
$upload->process($file);
} catch (Exception $exception) {
// Something went wrong. Log it.
Log::error($exception);
$error = array('name' => $file->getClientOriginalName(), 'size' => $file->getSize(), 'error' => $exception->getMessage());
// Return error
return Response::json($error, 400);
}
// If it now has an id, it should have been successful.
if ($upload->id) {
$newurl = URL::asset($upload->publicpath() . $upload->filename);
// this creates the response structure for jquery file upload
$success = new stdClass();
$success->name = $upload->filename;
$success->size = $upload->size;
$success->url = $newurl;
$success->thumbnailUrl = $newurl;
$success->deleteUrl = action('UploadController@delete', $upload->id);
$success->deleteType = 'DELETE';
$success->fileID = $upload->id;
return Response::json(array('files' => array($success)), 200);
} else {
return Response::json('Error', 400);
}
}
示例5: 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;
}
示例6: 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');
}
示例7: 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);
}
示例8: 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');
}
示例9: 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;
}
示例10: 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');
}
示例11: 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');
}
示例12: processImg
function processImg($img)
{
$upload = new Upload($img['picture']);
$upload->file_new_name_body = time();
foreach ($this->img_config['picture'] as $key => $value) {
$upload->{$key} = $value;
}
$upload->process($this->img_config['target_path']['picture']);
if (!$upload->processed) {
$msg = $this->generateError($upload->error);
return $this->redirect('create');
}
$return['file_dst_name'] = $upload->file_dst_name;
return $return;
}
示例13: 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()));
}
示例14: processAttachment
function processAttachment($img)
{
$upload = new Upload($img['attachment']);
$upload->file_new_name_body = time();
foreach ($this->img_config['attachment'] as $key => $value) {
$upload->{$key} = $value;
}
$upload->process($this->img_config['target_path']['attachment']);
if (!$upload->processed) {
$msg = $this->generateError($upload->error);
$this->Session->setFlash($msg);
return $this->redirect($this->referer());
}
$return['file_dst_name'] = $upload->file_dst_name;
return $return;
}
示例15: __construct
public function __construct($arrParam = null, $options = null)
{
$this->_arrData = $arrParam;
$this->_validate = \Validation::forge('validate');
//$this->_validate->add_field('file_process_data', 'File Data', 'required');
/*=======================================================
* Start - validate file_process_data
*=======================================================*/
if (!empty($_FILES['file_process_data']['name'])) {
$this->_upload = \Upload::process(array('path' => DOCROOT . 'files' . DS . 'sony_payment' . DS . 'file_data', 'ext_whitelist' => array('csv'), 'max_size' => '1024000000', 'suffix' => '_' . strtotime('now'), 'normalize' => true, 'auto_rename' => true));
if (!\Upload::is_valid()) {
$error = \Upload::get_errors('file_process_data');
$this->_arrError['file_process_data'] = $error['errors'][0]['message'];
}
} else {
$this->_arrError['file_process_data'] = 'アップロード名 は必須入力です。';
}
}