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


PHP Upload::valid方法代码示例

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


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

示例1: _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

示例2: _validation

 /**
  * Validation image file
  *
  * @return $this
  * @throws Exception
  */
 private function _validation()
 {
     if (!Upload::valid(Arr::get($_FILES, $this->_config['fn']))) {
         throw new Exception('Error field input name');
     }
     return Validation::factory($_FILES)->rule($this->_config['fn'], 'Upload::valid')->rule($this->_config['fn'], 'Upload::type', array(':value', array('jpg', 'jpeg', 'png', 'gif')))->rule($this->_config['fn'], 'Upload::size', array(':value', '10M'))->rule($this->_config['fn'], 'Upload::image');
 }
开发者ID:eok8177,项目名称:shopCMS,代码行数:13,代码来源:Fileuploaders.php

示例3: 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

示例4: validate_uploaded_image

 public static function validate_uploaded_image($image)
 {
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
         return FALSE;
     }
     return TRUE;
 }
开发者ID:Workhaven,项目名称:workhaven,代码行数:7,代码来源:Image.php

示例5: action_image

 public function action_image()
 {
     if (Core::post('photo_delete') and Auth::instance()->get_user()->delete_image() == TRUE) {
         Alert::set(Alert::SUCCESS, __('Photo deleted.'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
     }
     // end of photo delete
     //get image
     $image = $_FILES['profile_image'];
     //file post
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) && !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Is not valid format, please use one of this formats "jpg, jpeg, png"'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Is not of valid size. Size is limited on ' . core::config('general.max_image_size') . 'MB per image'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
         }
         Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Image is not valid. Please try again.'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
     } else {
         if ($image != NULL) {
             $user = Auth::instance()->get_user();
             // saving/uploadng zip file to dir.
             $root = DOCROOT . 'images/users/';
             //root folder
             $image_name = $user->id_user . '.png';
             $width = core::config('image.width');
             // @TODO dynamic !?
             $height = core::config('image.height');
             // @TODO dynamic !?
             $image_quality = core::config('image.quality');
             // if folder does not exist, try to make it
             if (!is_dir($root) and !@mkdir($root, 0775, TRUE)) {
                 // mkdir not successful ?
                 Alert::set(Alert::ERROR, __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.'));
                 return FALSE;
                 // exit function
             }
             // save file to root folder, file, name, dir
             if ($file = Upload::save($image, $image_name, $root)) {
                 // resize uploaded image
                 Image::factory($file)->orientate()->resize($width, $height, Image::AUTO)->save($root . $image_name, $image_quality);
                 // update category info
                 $user->has_image = 1;
                 $user->last_modified = Date::unix2mysql();
                 $user->save();
                 Alert::set(Alert::SUCCESS, $image['name'] . ' ' . __('Image is uploaded.'));
             } else {
                 Alert::set(Alert::ERROR, $image['name'] . ' ' . __('Icon file could not been saved.'));
             }
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
         }
     }
 }
开发者ID:Ryanker,项目名称:open-eshop,代码行数:56,代码来源:profile.php

示例6: save

 /**
  * Logic to deal with uploading the image file and generating thumbnails according to
  * what has been specified in the $thumbnails array.
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     $old_filename = $this->default;
     // 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, DIRECTORY_SEPARATOR);
             }
             // delete the old file
             $file_has_changed = $old_filename != $this->default;
             if ($file_has_changed and file_exists(realpath($this->path) . DIRECTORY_SEPARATOR . $old_filename)) {
                 unlink(realpath($this->path) . DIRECTORY_SEPARATOR . $old_filename);
             }
             // generate any thumbnails
             $source_file = $this->path . DIRECTORY_SEPARATOR . $value;
             foreach ($this->thumbnails as $thumbnail) {
                 $dest_path = realpath($thumbnail['path']) . DIRECTORY_SEPARATOR;
                 // Delete the old file
                 if ($file_has_changed and file_exists($dest_path . $old_filename)) {
                     unlink($dest_path . $old_filename);
                 }
                 $image = Image::factory($source_file);
                 if (isset($thumbnail['rotation'])) {
                     $image->rotate($thumbnail['rotation']);
                 }
                 $w = $thumbnail['dest_w'];
                 $h = $thumbnail['dest_h'];
                 switch ($thumbnail['resize_type']) {
                     case Jelly_Field_Image::RESIZE_TYPE_CROP:
                         $image->crop($w, $h);
                         break;
                     case Jelly_Field_Image::RESIZE_TYPE_FIT:
                         if ($image->width > $w || $image->height > $h) {
                             $image->resize($w, $h);
                         }
                         break;
                     case Jelly_Field_Image::RESIZE_TYPE_EXACT_FIT:
                         $image->resize($w, $h, Image::INVERSE)->crop($w, $h);
                         break;
                     case Jelly_Field_Image::RESIZE_TYPE_NONE:
                         // Do nothing - copy of the image will be saved below
                         break;
                 }
                 $image->save($dest_path . $value);
             }
         } else {
             $value = $old_filename;
         }
     }
     return $value;
 }
开发者ID:vitch,项目名称:kohana-jelly,代码行数:64,代码来源:image.php

示例7: action_create

 /**
  * CRUD controller: CREATE
  */
 public function action_create()
 {
     $this->auto_render = FALSE;
     $this->template = View::factory('js');
     if (!isset($_FILES['image'])) {
         $this->template->content = json_encode('KO');
         return;
     }
     $image = $_FILES['image'];
     if (core::config('image.aws_s3_active')) {
         require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
         $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
     }
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) and !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))));
             return;
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
         return;
     } elseif ($image != NULL) {
         // saving/uploading img file to dir.
         $path = 'images/cms/';
         $root = DOCROOT . $path;
         //root folder
         $image_name = URL::title(pathinfo($image['name'], PATHINFO_FILENAME));
         $image_name = Text::limit_chars(URL::title(pathinfo($image['name'], PATHINFO_FILENAME)), 200);
         $image_name = time() . '.' . $image_name;
         // if folder does not exist, try to make it
         if (!file_exists($root) and !@mkdir($root, 0775, true)) {
             // mkdir not successful ?
             $this->template->content = json_encode(array('msg' => __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')));
             return;
             // exit function
         }
         // save file to root folder, file, name, dir
         if ($file = Upload::save($image, $image_name, $root)) {
             // put image to Amazon S3
             if (core::config('image.aws_s3_active')) {
                 $s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $image_name, S3::ACL_PUBLIC_READ);
             }
             $this->template->content = json_encode(array('link' => Core::config('general.base_url') . $path . $image_name));
             return;
         } else {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image file could not been saved.')));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
     }
 }
开发者ID:JeffPedro,项目名称:project-garage-sale,代码行数:57,代码来源:cmsimages.php

示例8: _save_image

 protected function _save_image($image)
 {
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
         return FALSE;
     }
     $directory = DOCROOT . '/public/media/image_product/';
     if ($file = Upload::save($image, NULL, $directory)) {
         $filename = strtolower(Text::random('alnum', 20)) . '.jpg';
         Image::factory($file)->resize(500, 500, Image::AUTO)->save($directory . $filename);
         // Delete the temporary file
         unlink($file);
         return $filename;
     }
     return FALSE;
 }
开发者ID:piotrazsko,项目名称:sushi,代码行数:15,代码来源:Ajax.php

示例9: save_image

 /**
  * @return bool|string
  */
 private function save_image($image)
 {
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
         return FALSE;
     }
     $directory = DOCROOT . $this->prefix;
     if ($file = Upload::save($image, NULL, $directory)) {
         // Save the image.
         Image::factory($file)->resize($this->width(), $this->height())->save($directory . $this->_filename());
         // Delete the temporary file
         unlink($file);
         return TRUE;
     }
     return FALSE;
 }
开发者ID:modulargaming,项目名称:user,代码行数:18,代码来源:Upload.php

示例10: guess_type

 /**
  * Guess the type of the source:
  *
  *  - Upload_Source::TYPE_URL
  *  - Upload_Source::TYPE_STREAM
  *  - Upload_Source::TYPE_TEMP
  *  - Upload_Source::TYPE_FILE
  *  - Upload_Source::TYPE_UPLOAD
  *  - FALSE
  *
  * @param  mixed $source
  * @return string|boolean
  */
 public static function guess_type($source)
 {
     if (is_array($source)) {
         return (Upload::valid($source) and $source['error'] !== UPLOAD_ERR_NO_FILE) ? Upload_Source::TYPE_UPLOAD : FALSE;
     } elseif ($source == 'php://input') {
         return Upload_Source::TYPE_STREAM;
     } elseif (Valid::url($source)) {
         return Upload_Source::TYPE_URL;
     } elseif (substr_count($source, DIRECTORY_SEPARATOR) === 1) {
         return Upload_Source::TYPE_TEMP;
     } elseif (is_file($source)) {
         return Upload_Source::TYPE_FILE;
     } else {
         return FALSE;
     }
 }
开发者ID:openbuildings,项目名称:jam,代码行数:29,代码来源:Source.php

示例11: action_add

 public function action_add()
 {
     $user_id = $this->user->id;
     if (empty($user_id)) {
         $this->redirect('/');
     }
     $article = new Model_Article();
     $article->title = Arr::get($_POST, 'title');
     $article->description = Arr::get($_POST, 'description');
     $article->text = Arr::get($_POST, 'text');
     $cover = Arr::get($_FILES, 'cover');
     $errors = FALSE;
     $table_values = array();
     if ($article->title != '') {
         $table_values['title'] = array('value' => $article->title);
     } else {
         $errors = TRUE;
     }
     if ($article->description != '') {
         $table_values['description'] = array('value' => $article->description);
     } else {
         $errors = TRUE;
     }
     if ($article->text != '') {
         $table_values['text'] = array('value' => $article->text);
     } else {
         $errors = TRUE;
     }
     if (!Upload::valid($cover) or !Upload::not_empty($cover) or !Upload::type($cover, array('jpg', 'jpeg', 'png')) or !Upload::size($cover, '10M')) {
         $table_values['cover'] = TRUE;
         $errors = TRUE;
     }
     if ($errors) {
         // $this->view["editor"] = View::factory('templates/articles/editor', array("storedNodes" => $table_values['text']['value']));
         $content = View::factory('templates/articles/new', $this->view);
         $this->template->content = View::factory("templates/articles/wrapper", array("active" => "newArticle", "content" => $content));
         return false;
     }
     // getting new name for cover
     $article->cover = $this->methods->save_cover($cover);
     $article->user_id = $user_id;
     $article->is_published = true;
     // FIXME изменить, когда будет доступны режимы публикации
     $article->insert();
     // redirect to new article
     $this->redirect('/article/' . $article->id);
 }
开发者ID:Kapitonova,项目名称:codex,代码行数:47,代码来源:Action.php

示例12: action_upload

 public function action_upload()
 {
     $field = 'Filedata';
     if (($value = Arr::get($_FILES, $field, FALSE)) === FALSE) {
         $this->request->response = 'error';
         return;
     }
     if (!Upload::not_empty($value) or !Upload::valid($value)) {
         $this->request->response = 'error';
         return;
     }
     if ($tmp_name = Torn_Uploader::upload_to_cache($value, $field)) {
         $this->request->response = 'done;' . $tmp_name;
     } else {
         $this->request->response = 'error';
     }
 }
开发者ID:TdroL,项目名称:kohana-jelly-torn,代码行数:17,代码来源:torn.php

示例13: load

 /**
  * осуществляет проверку загружаемого изображения на jpg(jpeg)
  * копирует его в католог img, предварительно 
  * изменив размер до s - max(300*300) m  - max(800*800) схранив пропорции
  * @param $file    string  полное имя файла 
  * @return         mixed new file name or false(boolean)
  */
 public function load($file, $id = '')
 {
     if (!Upload::valid($file) || !Upload::not_empty($file) || !Upload::type($file, array('jpg', 'jpeg'))) {
         return false;
     }
     $dir = DOCROOT . self::IMAGE_DIR;
     if ($image = Upload::save($file, NULL, $dir)) {
         if ($id == '') {
             $id = Text::random('alnum', 32);
         }
         $name = $id . '.jpg';
         Image::factory($image)->resize(300, 300, Image::AUTO)->save($dir . 's_' . $name);
         Image::factory($image)->resize(800, 800, Image::AUTO)->save($dir . 'm_' . $name);
         unlink($image);
         return $name;
     }
     return false;
 }
开发者ID:Jurasikt,项目名称:kohana,代码行数:25,代码来源:photo.php

示例14: action_image

 public function action_image()
 {
     //get image
     $image = $_FILES['profile_image'];
     //file post
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) && !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Is not valid format, please use one of this formats "jpg, jpeg, png"'));
             $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Is not of valid size. Size is limited on ' . core::config('general.max_image_size') . 'MB per image'));
             $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
         }
         Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Image is not valid. Please try again.'));
         $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
     } else {
         if ($image != NULL) {
             $user_id = Auth::instance()->get_user()->id_user;
             // saving/uploadng zip file to dir.
             $root = DOCROOT . 'images/users/';
             //root folder
             $image_name = $user_id . '.png';
             $width = core::config('image.width');
             // @TODO dynamic !?
             $height = core::config('image.height');
             // @TODO dynamic !?
             $image_quality = core::config('image.quality');
             // if folder doesnt exists
             if (!file_exists($root)) {
                 mkdir($root, 775, true);
             }
             // save file to root folder, file, name, dir
             if ($file = Upload::save($image, $image_name, $root)) {
                 // resize uploaded image
                 Image::factory($file)->resize($width, $height, Image::AUTO)->save($root . $image_name, $image_quality);
             }
             Alert::set(Alert::SUCCESS, $image['name'] . ' ' . __('Image is uploaded.'));
             $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
         }
     }
 }
开发者ID:Wildboard,项目名称:WbWebApp,代码行数:42,代码来源:profile.php

示例15: _save_image

 protected function _save_image($image, $directory)
 {
     if (!Upload::valid($image) || !Upload::not_empty($image) || !Upload::type($image, array('jpg', 'jpeg', 'png', 'gif')) || !Upload::size($image, '2M')) {
         return false;
     }
     if (!is_dir($directory)) {
         mkdir($directory, 0777, true);
     }
     if ($file = Upload::save($image, NULL, $directory)) {
         try {
             $filename = Text::random('alnum', 20) . '.jpg';
             Image::factory($file)->save($directory . $filename);
             unlink($file);
             return $filename;
         } catch (ErrorException $e) {
             // ...
         }
     }
     return false;
 }
开发者ID:Nyaan,项目名称:meintagebuchonline,代码行数:20,代码来源:Media.php


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