当前位置: 首页>>代码示例>>PHP>>正文


PHP Upload::save方法代码示例

本文整理汇总了PHP中Upload::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::save方法的具体用法?PHP Upload::save怎么用?PHP Upload::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Upload的用法示例。


在下文中一共展示了Upload::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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');
 }
开发者ID:OICTH1,项目名称:Controlsystem,代码行数:35,代码来源:registration.php

示例2: addPortfolio

 public function addPortfolio($no)
 {
     $tempFileName = 'file' . rand(10000000, 99999999);
     $validationFiles = Validation::factory($_FILES)->rules('portfolioSmall', array(array('Upload::not_empty'), array('Upload::image')))->rules('portfolioBig', array(array('Upload::not_empty'), array('Upload::image')));
     $validationText = Validation::factory($_POST)->rule('name', 'not_empty');
     if ($validationFiles->check() and $validationText->check()) {
         Upload::save($validationFiles['portfolioSmall'], $tempFileName . '.png', Upload::$default_directory);
         Upload::save($validationFiles['portfolioBig'], $tempFileName . '.jpg', Upload::$default_directory);
         $tempFileNamePath = Upload::$default_directory . $tempFileName;
         $filePath = Kohana::$config->load('portfolio')->get('filePath');
         if (copy($tempFileNamePath . '.png', $filePath . $tempFileName . '.png') and copy($tempFileNamePath . '.jpg', $filePath . $tempFileName . '.jpg')) {
             unlink($tempFileNamePath . '.png');
             unlink($tempFileNamePath . '.jpg');
             $this->path = $tempFileName;
             $this->name = HTML::chars($_POST['name']);
             $this->type = HTML::chars($_POST['type']);
             if (!$no) {
                 $this->no = (int) $this->maxNoPortfolio() + 1;
             } else {
                 $this->no = $no;
             }
             $this->create();
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
开发者ID:alex-bro,项目名称:olgabro.repo,代码行数:30,代码来源:Portfolio.php

示例3: _upload_image

 public function _upload_image(Validate $array, $input)
 {
     if ($array->errors()) {
         // Don't bother uploading
         return;
     }
     // Get the image from the array
     $image = $array[$input];
     if (!Upload::valid($image) or !Upload::not_empty($image)) {
         // No need to do anything right now
         return;
     }
     if (Upload::valid($image) and Upload::type($image, $this->types)) {
         $filename = strtolower(Text::random('alnum', 20)) . '.jpg';
         if ($file = Upload::save($image, NULL, $this->directory)) {
             Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename);
             // Update the image filename
             $array[$input] = $filename;
             // Delete the temporary file
             unlink($file);
         } else {
             $array->error('image', 'failed');
         }
     } else {
         $array->error('image', 'valid');
     }
 }
开发者ID:bosoy83,项目名称:progtest,代码行数:27,代码来源:image.php

示例4: actionBasicExecute

 /**
  * 上传
  */
 public function actionBasicExecute()
 {
     if (XUtils::method() == 'POST') {
         $adminiUserId = self::_sessionGet('adminiUserId');
         $file = XUpload::upload($_FILES['imgFile']);
         if (is_array($file)) {
             $model = new Upload();
             $model->user_id = intval($accountUserId);
             $model->file_name = $file['pathname'];
             $model->thumb_name = $file['paththumbname'];
             $model->real_name = $file['name'];
             $model->file_ext = $file['extension'];
             $model->file_mime = $file['type'];
             $model->file_size = $file['size'];
             $model->save_path = $file['savepath'];
             $model->hash = $file['hash'];
             $model->save_name = $file['savename'];
             $model->create_time = time();
             if ($model->save()) {
                 exit(CJSON::encode(array('state' => 'success', 'fileId' => $model->id, 'realFile' => $model->real_name, 'message' => '上传成功', 'file' => $file['pathname'])));
             } else {
                 @unlink($file['pathname']);
                 exit(CJSON::encode(array('state' => 'error', 'message' => '数据写入失败,上传错误')));
             }
         } else {
             exit(CJSON::encode(array('error' => 1, 'message' => '上传错误')));
         }
     }
 }
开发者ID:zywh,项目名称:maplecity,代码行数:32,代码来源:UploadifyController.php

示例5: upload

 /**
  * Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed
  * @param  string  $field             The name of the $_FILES field you want to upload
  * @param  boolean $upload_type       The type of upload ('news', 'gallery', 'section') etc
  * @param  boolean $type_id           The ID of the item (above) that the upload is linked to
  * @param  boolean $remove_existing   Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new one is uploaded for example)
  * @return object                     Returns the upload object so we can work with the uploaded file and details
  */
 public static function upload($field = 'image', $upload_type = false, $type_id = false, $remove_existing = false)
 {
     if (!$field || !$upload_type || !$type_id) {
         return false;
     }
     $input = Input::file($field);
     if ($input && $input['error'] == UPLOAD_ERR_OK) {
         if ($remove_existing) {
             static::remove($upload_type, $type_id);
         }
         $ext = File::extension($input['name']);
         $filename = Str::slug(Input::get('title'), '-');
         Input::upload('image', './uploads/' . $filename . '.' . $ext);
         $upload = new Upload();
         $upload->link_type = $upload_type;
         $upload->link_id = $type_id;
         $upload->filename = $filename . '.' . $ext;
         if (Koki::is_image('./uploads/' . $filename . '.' . $ext)) {
             $upload->small_filename = $filename . '_small' . '.' . $ext;
             $upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
             $upload->image = 1;
         }
         $upload->extension = $ext;
         $upload->user_id = Auth::user()->id;
         $upload->save();
         return $upload;
     }
 }
开发者ID:victoroliveira1605,项目名称:Laravel-Bootstrap,代码行数:36,代码来源:uploadr.php

示例6: store

 /**
  * Upload the file and store
  * the file path in the DB.
  */
 public function store()
 {
     // Rules
     $rules = array('name' => 'required', 'file' => 'required|max:20000');
     $messages = array('max' => 'Please make sure the file size is not larger then 20MB');
     // Create validation
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $directory = "uploads/files/";
     // Before anything let's make sure a file was uploaded
     if (Input::hasFile('file') && Request::file('file')->isValid()) {
         $current_file = Input::file('file');
         $filename = Auth::id() . '_' . $current_file->getClientOriginalName();
         $current_file->move($directory, $filename);
         $file = new Upload();
         $file->user_id = Auth::id();
         $file->project_id = Input::get('project_id');
         $file->name = Input::get('name');
         $file->path = $directory . $filename;
         $file->save();
         return Redirect::back();
     }
     $upload = new Upload();
     $upload->user_id = Auth::id();
     $upload->project_id = Input::get('project_id');
     $upload->name = Input::get('name');
     $upload->path = $directory . $filename;
     $upload->save();
     return Redirect::back();
 }
开发者ID:pradeep1899,项目名称:ALM_Task_Manager,代码行数:36,代码来源:FilesController.php

示例7: save

 /**
  * Uploads a file if we have a valid upload
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     $original = $model->get($this->name, FALSE);
     // Upload a file?
     if (is_array($value) and Upload::valid($value)) {
         if (FALSE !== ($filename = Upload::save($value, NULL, $this->path))) {
             // Chop off the original path
             $value = str_replace(realpath($this->path) . DIRECTORY_SEPARATOR, '', $filename);
             // Ensure we have no leading slash
             if (is_string($value)) {
                 $value = trim($value, '/');
             }
             // Delete the old file if we need to
             if ($this->delete_old_file and $original != $this->default) {
                 $path = realpath($this->path) . $original;
                 if (file_exists($path)) {
                     unlink($path);
                 }
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
开发者ID:vitch,项目名称:kohana-jelly,代码行数:33,代码来源:file.php

示例8: 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);
 }
开发者ID:eva-tuantran,项目名称:use-knife-solo-instead-chef-solo-day13,代码行数:39,代码来源:image.php

示例9: action_upload

 public function action_upload()
 {
     $data = array();
     $data['errors'] = array();
     if ($this->isPressed('btnSubmit')) {
         $user = ORM::factory('user');
         $file = Validation::factory($_FILES);
         $file->rule('codesFile', 'Upload::not_empty');
         $file->rule('codesFile', 'Upload::valid');
         $file->rule('codesFile', 'Upload::type', array(':value', array('csv')));
         $file->rule('codesFile', 'Upload::size', array(':value', '1M'));
         if ($file->check()) {
             $savedfilename = Upload::save($file['codesFile'], 'tmpCodesList.csv', 'files');
             if ($savedfilename === FALSE) {
                 throw new Exception('Unable to save tmpCodesList.csv file!');
             }
             $data['errors'] = $user->importUsers($savedfilename);
             unlink($savedfilename);
             if (count($data['errors']) == 0) {
                 $data['success'] = TRUE;
             }
         } else {
             $data['errors'] = $file->errors('upload', FALSE);
         }
     }
     $this->tpl->content = View::factory('admin/uploadusers', $data);
 }
开发者ID:reznikds,项目名称:Reznik,代码行数:27,代码来源:users.php

示例10: 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;
 }
开发者ID:aminh047,项目名称:pepperyou,代码行数:37,代码来源:gallery.php

示例11: store

 /**
  * Store a newly created upload in storage.
  *
  * @return Response
  */
 public function store()
 {
     Upload::setRules('store');
     if (!Upload::canCreate()) {
         return $this->_access_denied();
     }
     $file = Input::file('file');
     $hash = md5(microtime() . time());
     $data = [];
     $data['path'] = public_path() . '/uploads/' . $hash . '/';
     mkdir($data['path']);
     $data['url'] = url('uploads/' . $hash);
     $data['name'] = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $file->getClientOriginalName());
     $data['type'] = $file->getMimeType();
     $data['size'] = $file->getSize();
     $data['uploadable_type'] = Request::header('X-Uploader-Class');
     $data['uploadable_id'] = Request::header('X-Uploader-Id') ? Request::header('X-Uploader-Id') : 0;
     $data['token'] = Request::header('X-CSRF-Token');
     $file->move($data['path'], $data['name']);
     if (property_exists($data['uploadable_type'], 'generate_image_thumbnails')) {
         Queue::push('ThumbnailService', array('path' => $data['path'] . '/' . $data['name']));
     }
     $upload = new Upload();
     $upload->fill($data);
     if (!$upload->save()) {
         return $this->_validation_error($upload);
     }
     if (Request::ajax()) {
         return Response::json($upload, 201);
     }
     return Redirect::back()->with('notification:success', $this->created_message);
 }
开发者ID:k4ml,项目名称:laravel-base,代码行数:37,代码来源:UploadsController.php

示例12: action_save

 public function action_save()
 {
     if ($_POST && $_FILES) {
         $imageChanged = false;
         $data = (object) $this->sanitize($_POST);
         $update = false;
         if ($data->id == "") {
             $editorial = ORM::factory("editorial");
         } else {
             $editorial = ORM::factory("editorial", $data->id);
         }
         if (in_array($_FILES['image']['type'], $this->allowed)) {
             Upload::$default_directory = Kohana::config('myshot.basePath');
             if ($stage_path = Upload::save($_FILES['image'])) {
                 $imageChanged = true;
                 Library_Akamai::factory()->addToDir($stage_path, 'editorials');
             }
         }
         $editorial->title = $data->title;
         $editorial->image = $imageChanged ? Kohana::config('myshot.cdn') . 'editorials/' . basename($stage_path) : $editorial->image;
         $editorial->image_alt = $data->image_alt;
         $editorial->link = $data->link;
         $editorial->link_text = $data->link_text;
         $editorial->text = $data->text;
         $editorial->save();
         Message::set(Message::SUCCESS, $update ? "You have sucessfully updated the editorial." : "You have sucessfully added the editorial.");
     }
     Request::instance()->redirect('admin/editorials');
 }
开发者ID:natgeo,项目名称:kids-myshot,代码行数:29,代码来源:editorials.php

示例13: uploadfile

 public function uploadfile()
 {
     if ($_GET['from'] == 'swfupload') {
         $uid = intval($_GET['uid']);
         $username = trim($_GET['username']);
         $token = sha1($uid . $username . formhash());
         if (!$uid || !$username || $token != $_GET['token']) {
             echo json_encode(array('state' => 0, 'info' => 'nologin'));
             exit;
         }
     } else {
         $this->_checkuser();
         $uid = $this->uid;
     }
     $config = $GLOBALS['G']['config']['output'];
     $upload = new Upload();
     $attachment = 'attach/' . date('Y') . '/' . date('m') . '/' . $upload->setfilename();
     if ($upload->save(ROOT_PATH . '/' . $config['attachdir'] . '/' . $attachment)) {
         $attachdata = array('uid' => $uid, 'attachname' => $upload->oriname(), 'attachment' => $attachment, 'attachsize' => $upload->size(), 'attachtype' => $upload->type(), 'attachtime' => time());
         $attachdata['attachid'] = $this->t('attachment')->insert($attachdata, true);
         echo json_encode(array('state' => 1, 'data' => $attachdata));
         exit;
     } else {
         echo json_encode(array('state' => 0, 'info' => 'Upload Failed(' . $upload->error . ')'));
         exit;
     }
 }
开发者ID:xy113,项目名称:XiangBaLaoServer,代码行数:27,代码来源:class.MiscController.php

示例14: actionUpload

 /**
  * 编辑器文件上传
  */
 public function actionUpload()
 {
     if (XUtils::method() == 'POST') {
         $file = XUpload::upload($_FILES['imgFile']);
         if (is_array($file)) {
             $model = new Upload();
             $model->user_id = intval($admini['userId']);
             $model->file_name = CHtml::encode($file['pathname']);
             $model->thumb_name = CHtml::encode($file['paththumbname']);
             $model->real_name = CHtml::encode($file['name']);
             $model->file_ext = $file['extension'];
             $model->file_mime = $file['type'];
             $model->file_size = $file['size'];
             $model->save_path = $file['savepath'];
             $model->hash = $file['hash'];
             $model->save_name = $file['savename'];
             $model->create_time = time();
             if ($model->save()) {
                 exit(CJSON::encode(array('error' => 0, 'url' => Yii::app()->baseUrl . '/' . $file['pathname'])));
             } else {
                 @unlink($file['pathname']);
                 @unlink($file['paththumbname']);
                 exit(CJSON::encode(array('error' => 1, 'message' => '上传错误')));
             }
         } else {
             exit(CJSON::encode(array('error' => 1, 'message' => '上传错误:' . $file)));
         }
     }
 }
开发者ID:tecshuttle,项目名称:51qsk,代码行数:32,代码来源:XUserBase.php

示例15: action_index

 /**
  * 首页
  *
  */
 public function action_index()
 {
     if (!empty($_FILES)) {
         $savePath = DOCROOT . 'src_csv/' . $this->auth['uid'] . '/';
         // 保存目录
         $upload = new Upload(array('size' => 10240, 'ext' => array('csv')));
         $upload->set_path($savePath);
         try {
             $result = $upload->save($_FILES['upload_file']);
             $date = array($this->auth['uid'], $this->auth['username'], $result['name'], $result['saveName'], $result['size'], date('Y-m-d H:i:s'));
             $row = DB::insert('imgup_movestore', array('uid', 'uname', 'csv_file', 'src_file', 'freesize', 'upload_time'))->values($date)->execute();
             $content = $this->changeCharacter($savePath . $result['saveName']);
             //preg_match_all("/(src)=[\"|'| ]{0,}((https?\:\/\/.*?)([^>]*[^\.htm]\.(gif|jpg|bmp|png)))/i",$content, $match);
             //preg_match_all("/[\"|'| ]{0,}((https?\:\/\/[a-zA-Z0-9_\.\/]*?)([^<\>]*[^\.htm]\.(gif|jpg|bmp|png)))/i", $content, $match);
             preg_match_all("/\\<img.*?src\\=[\"\\']+[ \t\n]*(https?\\:\\/\\/.*?)[ \t\n]*[\"\\']+[^>]*>/i", $content, $match);
             $imgArr = array_unique($match[1]);
             foreach ($imgArr as $value) {
                 # 去除本站的图片地址
                 if (!preg_match("/^http:\\/\\/[\\w\\.\\-\\_]*wal8\\.com/i", $value)) {
                     DB::insert('store_imgs', array('sid', 'url', 'add_time', 'uid'))->values(array($row[0], $value, time(), $this->auth['uid']))->execute();
                 }
             }
             $link[] = array('text' => '返回', 'href' => '/shopmove');
             $this->show_message('上传' . $result['name'] . '文件成功', 1, $link);
         } catch (Exception $e) {
             $link[] = array('text' => '返回', 'href' => '/shopmove');
             $this->show_message($e->getMessage(), 0, $link);
         }
     }
 }
开发者ID:BGCX261,项目名称:zhongyycode-svn-to-git,代码行数:34,代码来源:shopmove.php


注:本文中的Upload::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。