Exemple #1
0
 function do_upload()
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . './phpexcel/');
     //set_include_path(' http://localhost/PHPExcel/phpexcel/');
     /** PHPExcel */
     include 'PHPExcel.php';
     /** PHPExcel_IOFactory */
     include 'PHPExcel/IOFactory.php';
     /** include php_excel5 */
     include 'PHPExcel/Reader/Excel5.php';
     include 'uploader.php';
     $uploader = new Helper_Uploader();
     $max_size = $uploader->allowedUploadSize();
     // 允许上传的最大值
     $final = array('message' => "", 'content' => array());
     if (!$uploader->existsFile('userfile')) {
         $final['message'] = '没有选择上传文件,或者文件上传失败';
     }
     //取得要上传的文件句柄
     if ($final['message'] == "") {
         $file = $uploader->file('userfile');
     }
     $results = $this->excel_read($file->filepath());
     $results = $this->format($results);
     $amount_list = array();
     foreach ($results as $key => $item) {
         if (isset($item['yuanbao_amount'])) {
             $amount_item['yuanbao_extra'] = round($item['yuanbao_amount'] / 4);
             $amount_item['yuanbao_amount'] = $item['yuanbao_amount'] - $amount_item['yuanbao_extra'];
             $amount_item['yuanbao_huodong'] = round($item['yuanbao_amount'] / 10);
         } else {
             $amount_item['yuanbao_extra'] = $item['extra_yuanbao'];
             $amount_item['yuanbao_amount'] = $item['basic_yuanbao'];
             $amount_item['yuanbao_huodong'] = $item['huodong_yuanbao'];
         }
         $amount_item['pay_type_id'] = $item['pay_type_id'];
         $amount_item['method_id'] = $item['method_id'];
         $amount_item['domain_name'] = $item['domain_name'];
         $amount_item['game_id'] = $item['game_id'];
         $amount_item['pay_amount'] = $item['pay_amount'];
         $amount_item['goods_id'] = $item['goods_id'];
         $amount_item['currency_id'] = $item['currency'];
         array_push($amount_list, $amount_item);
     }
     $this->pay_model->insert_pay_amount_batch($amount_list);
     print_r($amount_list);
     $this->load->view('upload', array('error' => 'success'));
 }
 /**
  * 构造函数
  */
 function __construct()
 {
     if (self::$_init) {
         return;
     }
     self::$_init = true;
     self::$_files = new QColl('Helper_Uploader_File');
     foreach ($_FILES as $field_name => $postinfo) {
         if (!isset($postinfo['error'])) {
             continue;
         }
         if (is_array($postinfo['error'])) {
             // 多文件上传
             foreach ($postinfo['error'] as $offset => $error) {
                 if ($error == UPLOAD_ERR_OK) {
                     $file = new Helper_Uploader_File($postinfo, $field_name, $offset);
                     self::$_files["{$field_name}{$offset}"] = $file;
                 }
             }
         } else {
             if ($postinfo['error'] == UPLOAD_ERR_OK) {
                 self::$_files[$field_name] = new Helper_Uploader_File($postinfo, $field_name);
             }
         }
     }
 }
 function validate($data, &$failed = null)
 {
     $ret = parent::validate($data);
     $id = $this->_upload_element->id;
     $uploader = new Helper_Uploader();
     try {
         if (!$uploader->existsFile($id)) {
             if ($this->_skip_upload_enabled) {
                 return $ret;
             }
             throw new QException('没有正确上传文件');
         }
         $file = $uploader->file($id);
         $errors = array();
         if (!$file->isValid($this->_upload_allowed_types)) {
             $errors[] = '上传文件的类型不符合要求';
         }
         if ($file->filesize() > $this->_upload_allowed_size) {
             $errors[] = '上传文件的大小超过限制';
         }
         if (empty($errors)) {
             $this->_upload_element->value = $file;
             return $ret;
         }
         $failed[] = $id;
         $this->_upload_element->invalidate(implode(', ', $errors));
         return false;
     } catch (Exception $ex) {
         $this->_upload_element->invalidate($ex->getMessage());
         return false;
     }
 }
Exemple #4
0
 public function update_money_flow_data()
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . './phpexcel/');
     //set_include_path(' http://localhost/PHPExcel/phpexcel/');
     /** PHPExcel */
     include 'PHPExcel.php';
     /** PHPExcel_IOFactory */
     include 'PHPExcel/IOFactory.php';
     /** include php_excel5 */
     include 'PHPExcel/Reader/Excel5.php';
     include 'uploader.php';
     $uploader = new Helper_Uploader();
     $max_size = $uploader->allowedUploadSize();
     // 允许上传的最大值
     $final = array('message' => "", 'content' => array());
     if (!$uploader->existsFile('money_flow')) {
         $final['message'] = '没有选择上传文件,或者文件上传失败';
     }
     //取得要上传的文件句柄
     if ($final['message'] == "") {
         $file = $uploader->file('money_flow');
     }
     $results = $this->excel_read($file->filepath());
     $results = $this->format($results);
     var_dump('sfdsf');
     die;
 }
Exemple #5
0
 /**
  * 执行上传文件
  *
  * @param QDB_ActiveRecord_Abstract $obj
  */
 function _exec_upload(QDB_ActiveRecord_Abstract $obj)
 {
     if (empty($this->_settings['upload_config'])) {
         return;
     }
     $uploader = new Helper_Uploader();
     $error = array();
     foreach ($this->_settings['upload_config'] as $file_id => $config) {
         //必需
         $post_key = isset($config['post_key']) ? $config['post_key'] : $file_id;
         if (!$uploader->existsFile($post_key)) {
             if (isset($config['required']) && $config['required']) {
                 if ($obj->id() && !empty($obj->{$file_id})) {
                     $obj->willChanged($file_id);
                 } else {
                     $error[$post_key]['required'] = $config['errmsgs']['required'];
                 }
             }
             continue;
         }
         $file = $uploader->file($post_key);
         $filename = $file->filename();
         $extname = $file->extname();
         // 验证文件类型
         if (isset($config['allowed_filetypes']) && $config['allowed_filetypes']) {
             if (!$file->isValid($config['allowed_filetypes'])) {
                 $error[$post_key]['allowed_filetypes'] = $config['errmsgs']['allowed_filetypes'];
                 continue;
             }
         } else {
             if ($file->isValid('.php')) {
                 $error[$post_key]['allowed_filetypes'] = "PHP 文件是不允许上传的.";
                 continue;
             }
         }
         //验证文件大小
         if (isset($config['max_size']) && $config['max_size'] > 0) {
             if ($file->filesize() > $config['max_size'] * 1024) {
                 $error[$post_key]['max_size'] = $config['errmsgs']['max_size'];
                 continue;
             }
         }
         // 验证图片尺寸
         if (isset($config['image_dimension']) && $config['image_dimension']) {
             list($width, $height, $type, $attr) = getimagesize($file->filepath());
             if (!$width || !$height) {
                 continue;
             }
             list($dim_width, $dim_height) = explode('*', $config['image_dimension']);
             if (isset($dim_width) && $dim_width > 0 && $dim_width != $width || isset($dim_height) && $dim_height > 0 && $dim_height != $height) {
                 $error[$post_key]['image_dimension'] = $config['errmsgs']['image_dimension'];
                 continue;
             }
         }
         $dir = rtrim($config['upload_dir'], '/\\') . DS;
         $date = date('Y-m');
         $dest_dir = $dir . $date;
         Helper_Filesys::mkdirs($dest_dir);
         $md5 = md5($filename . '-' . microtime(true));
         $_prop_filename = '';
         //如果上图片
         if (isset($config['is_image']) && $config['is_image'] || isset($config['large']) || isset($config['thumb'])) {
             $pic_filename = $md5 . '.jpg';
             $image = Helper_Image::createFromFile($file->filepath(), $file->extname());
             // 生成大图
             if (isset($config['large'])) {
                 list($w, $h) = explode('*', $config['large']);
                 $image->crop($w, $h);
             }
             $image->saveAsJpeg($dest_dir . DS . $pic_filename);
             $_prop_filename = "{$date}/{$pic_filename}";
             // 生成缩略图
             if (isset($config['thumb'])) {
                 $thumb_filename = $md5 . '-thumb.jpg';
                 list($w, $h) = explode('*', $config['thumb']);
                 $image->crop($w, $h);
                 $image->saveAsJpeg($dest_dir . DS . $thumb_filename);
             }
             // 销毁图片资源并删除上传文件
             $image->destroy();
             $file->unlink();
         } else {
             $file_name = $md5 . '.' . $extname;
             $file->move($dest_dir . DS . $file_name);
             $_prop_filename = "{$date}/{$file_name}";
         }
         //如果是更新,删除原有的
         if ($obj->id() && !empty($obj->{$file_id})) {
             $this->_delete_upload_file($obj, $file_id);
         }
         //向属性负值
         $obj->{$file_id} = $_prop_filename;
     }
     if (!empty($error)) {
         throw new QDB_ActiveRecord_ValidateFailedException($error, $obj);
     }
 }
Exemple #6
0
 /**
  * 初始化上传
  */
 protected function _init()
 {
     if (self::$_init) {
         return;
     }
     self::$_init = true;
     if (!$this->context->isPOST()) {
         return;
     }
     if (empty($_FILES)) {
         self::$_files = array();
         return;
     }
     foreach ($_FILES as $field_name => $postinfo) {
         if (!isset($postinfo['error'])) {
             continue;
         }
         if (is_array($postinfo['error'])) {
             // 多文件上传
             foreach ($postinfo['error'] as $offset => $error) {
                 if ($error == UPLOAD_ERR_OK) {
                     $file = new Helper_UploadFile($postinfo, $field_name, $offset);
                     self::$_files["{$field_name}{$offset}"] = $file;
                 }
             }
         } else {
             if ($postinfo['error'] == UPLOAD_ERR_OK) {
                 self::$_files[$field_name] = new Helper_UploadFile($postinfo, $field_name);
             }
         }
     }
 }