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


PHP upload::valid方法代码示例

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


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

示例1: 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($this->path, '', $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 = $this->path . $original;
                 if (file_exists($path)) {
                     unlink($path);
                 }
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
开发者ID:rcapp,项目名称:kohana-jelly,代码行数:33,代码来源:file.php

示例2: attach_uploaded_file

 public function attach_uploaded_file($field, $upload)
 {
     if (!upload::valid($upload)) {
         throw new Kohana_User_Exception('Not A Valid Upload', 'The supplied array did not specify a valid uploaded file');
     }
     $this->remove_file($field);
     $this->files_pending_attachment[$field] = array($upload, 'upload');
 }
开发者ID:evansd-archive,项目名称:kohana-module--files,代码行数:8,代码来源:ORM_Files.php

示例3: _save_img_bg

 protected function _save_img_bg($image)
 {
     if (!upload::valid($image) or !upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
         $this->session->set_flash('error_msg', 'Only upload file jpg , jpeg , png , gif');
         url::redirect('admin_config');
     } else {
         $directory = DOCROOT . 'themes/client/styleSIC/index/pics/';
         if ($file = upload::save($image, NULL, $directory)) {
             $filename = 'bg_' . md5(rand(0, 999)) . time() . '.png';
             Image::factory($file)->save($directory . $filename);
             // Delete the temporary file
             unlink($file);
             return $filename;
         }
         return FALSE;
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:17,代码来源:admin_config.php

示例4: 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)
 {
     // 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);
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
开发者ID:jerfowler,项目名称:kohana-jelly,代码行数:25,代码来源:file.php

示例5: upload

 public function upload()
 {
     if (!$_FILES) {
         return;
     }
     $surfix = Kohana::config('torn')->surfix->temp;
     $surfix_len = utf8::strlen($surfix);
     foreach ($_POST as $key => $tmp_name) {
         if (utf8::substr($key, -$surfix_len) == $surfix) {
             $field = utf8::substr($key, 0, -$surfix_len);
             $this->parent->model->set($field, $tmp_name);
         }
     }
     $cache = Cache::instance();
     foreach ($_FILES as $key => $upload) {
         $this->parent->model->set($key, $upload);
         if (!isset($this->parent->fields[$key]) or !$this->parent->fields[$key] instanceof Torn_Field_File) {
             continue;
         }
         if (upload::not_empty($upload) and upload::valid($upload)) {
             $seed = Arr::get($_POST, '__SEED__', md5(Request::current()->uri() . time()));
             $tmp_name = $seed . '-' . md5_file($upload['tmp_name']);
             if (upload::save($upload, $tmp_name, Kohana::$cache_dir) !== FALSE) {
                 $timestamp = 24 * 60 * 60;
                 $cache->set($tmp_name, array('upload' => $upload, 'timestamp' => $timestamp), $timestamp);
                 $tmp_old_file = Arr::get($_POST, $key . $surfix);
                 if (!empty($tmp_old_file) and file_exists(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file)) {
                     try {
                         unlink(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file);
                         $cache->delete($tmp_old_file);
                     } catch (Exception $e) {
                     }
                 }
                 $this->parent->model->set($key, $tmp_name);
             }
         }
     }
 }
开发者ID:TdroL,项目名称:kohana-jelly-torn,代码行数:38,代码来源:helper.php

示例6: _save_img_s3

 protected function _save_img_s3($image)
 {
     require Kohana::find_file('views/aws', 'init');
     if (!upload::valid($image) or !upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
         $this->session->set_flash('error_msg', 'Only upload file jpg , jpeg , png , gif');
         ///url::redirect('admin_config');
         //die();
         return FALSE;
     } else {
         $name = $image['name'];
         $size = $image['size'];
         $tmp = $image['tmp_name'];
         $actual_image_name = 'ans_' . md5($image['name'] . time()) . "." . 'png';
         try {
             // Upload data.
             $result = $s3Client->putObject(array('Bucket' => $s3_bucket, 'Key' => 'answer/' . $actual_image_name, 'SourceFile' => $this->s3_resize($tmp, 593, 539), 'ACL' => 'public-read', 'ContentType' => 'image/png'));
             return $actual_image_name;
         } catch (S3Exception $e) {
             return FALSE;
         }
         return FALSE;
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:23,代码来源:admin_questionnaires.php

示例7: _save_img_courses

 protected function _save_img_courses($image, $hd_id = '')
 {
     if (!upload::valid($image) or !upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
         $this->session->set_flash('error_msg', 'Only upload file jpg , jpeg , png , gif');
         if ($hd_id) {
             url::redirect('admin_test/edit/' . $hd_id);
         } else {
             url::redirect('admin_test/create');
         }
     } else {
         $directory = DOCROOT . 'uploads/courses_img/';
         if ($file = upload::save($image, NULL, $directory)) {
             $filename = md5(rand(0, 999)) . '.png';
             Image::factory($file)->resize(200, 200, Image::AUTO)->save($directory . $filename);
             // Delete the temporary file
             unlink($file);
             return $filename;
         }
         return FALSE;
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:21,代码来源:admin_test.php

示例8: index

 /**
  * Add Edit decayimage 
  */
 public function index()
 {
     // The default decayimage thumb file name
     $default_decayimage_thumb = 'Question_icon_thumb.png';
     $this->template->content = new View('decayimage/settings');
     $this->template->content->title = Kohana::lang('decayimage.decayimage');
     plugin::add_stylesheet('decayimage/css/decayimage');
     // Setup and initialize form field names
     $form = array('action' => '', 'decayimage_id' => '', 'decayimage_image' => '', 'decayimage_file' => '', 'decayimage_thumb' => '', 'category_id' => '');
     // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     $parents_array = array();
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim');
         $post->add_callbacks('category_id', array($this, '_is_valid_category'));
         // if we have an action == 'a' but and a decayimage_id then what we really
         // mean is to perform and edit
         if ($post->action == 'a' && isset($post->category_id)) {
             $post->add_rules('category_id', 'required', 'numeric');
             if ($post->validate() && ($decayimage = ORM::factory('decayimage')->where('category_id', $post->category_id)->find()) && $decayimage->loaded) {
                 $post->decayimage_id = $decayimage->id;
                 $post->action = 'e';
             }
         }
         // Check for action
         if ($post->action == 'a') {
             // Create a new decayimage row
             $decayimage = new Decayimage_Model($post->decayimage_id);
             // Handle the case where we recieve new files
             if (upload::valid($_FILES['decayimage_file']) && strlen($_FILES['decayimage_file']['name']) && ($_FILES = Validation::factory($_FILES)->add_rules('decayimage_file', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]')) && $_FILES->validate() && $post->validate()) {
                 // Upload the file and create a thumb
                 $modified_files = $this->_handle_new_decayimage_fileupload(0);
                 if (!$modified_files) {
                     $form_saved = false;
                     $form_error = TRUE;
                     $post->add_error('decayimage', Kohana::lang('decayimage.cant_upload_file'));
                 } else {
                     $decayimage->decayimage_image = $modified_files[0];
                     $decayimage->decayimage_thumb = $modified_files[1];
                     // Update the relevant decayimage from the db
                     $decayimage->category_id = $post->category_id;
                     $decayimage->save();
                     $form_saved = TRUE;
                     $form_action = Kohana::lang('decayimage.added');
                 }
             } else {
                 if ($post->add_rules('decayimage_thumb', 'required', 'length[5,255]') && $post->add_callbacks('decayimage_thumb', array($this, '_is_valid_decayimage_thumb')) && $post->validate()) {
                     // Upload the file and create a thumb
                     $decayimage->decayimage_thumb = $post->decayimage_thumb;
                     // Update the relevant decayimage from the db
                     $decayimage->category_id = $post->category_id;
                     $decayimage->save();
                     $form_saved = TRUE;
                     $form_action = Kohana::lang('decayimage.added');
                 } else {
                     // There was an error in validation
                     $form_error = TRUE;
                     $form = arr::overwrite($form, $post->as_array());
                     $errors = arr::overwrite($errors, $post->errors('decayimage'));
                 }
             }
         } elseif ($post->action == 'e') {
             // Setup validation for new $_FILES
             if (upload::valid($_FILES['decayimage_file']) && strlen($_FILES['decayimage_file']['name'])) {
                 $_FILES = Validation::factory($_FILES)->add_rules('decayimage_file', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]');
             } else {
                 $post->add_rules('decayimage_thumb', 'required', 'length[5,255]');
                 $post->add_callbacks('decayimage_thumb', array($this, '_is_valid_decayimage_thumb'));
             }
             // Validate all input
             $post->add_rules('decayimage_id', 'required', 'numeric');
             $post->add_callbacks('decayimage_id', array($this, '_is_valid_decayimage_id'));
             if ($post->validate()) {
                 // Get the relevant decayimage from the db
                 $decayimage = new Decayimage_Model($post->decayimage_id);
                 // If a file was uploaded we will need to convert it to an apropriate icon size
                 if (upload::valid($_FILES['decayimage_file']) && strlen($_FILES['decayimage_file']['name']) && $_FILES->validate()) {
                     $modified_files = $this->_handle_new_decayimage_fileupload($post->decayimage_id);
                     if (!$modified_files) {
                         $form_saved = false;
                         $form_error = TRUE;
                         $post->add_error('decayimage', Kohana::lang('decayimage.cant_upload_file'));
                     } else {
                         $decayimage->decayimage_image = $modified_files[0];
                         $decayimage->decayimage_thumb = $modified_files[1];
                     }
                 } else {
                     $decayimage->decayimage_thumb = $post->decayimage_thumb;
                 }
                 // Update the relevant decayimage from the db
                 $decayimage->category_id = $post->category_id;
                 $decayimage->save();
//.........这里部分代码省略.........
开发者ID:rjmackay,项目名称:decayimage,代码行数:101,代码来源:decayimage_settings.php


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