vi 图片上传封装函数

public function uploadImage($userfile = 'userfile'){
  //公共部分不作为参数,可变部分作为参数
  /*
  $config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'gif|jpg|png';
  $config['max_size'] = '2000';
  $config['max_width'] = '1024';
  $config['max_height'] = '768';*/
  $config = $this->config->item('upload_image');
  $config['file_name'] = date("YmdHis").rand(100,999);

  $this->load->library('upload', $config);
  $this->upload->initialize($config);
  //参数:$_FILES数组的标签
  if($this->upload->do_upload($userfile)){
   $fileInfo = $this->upload->data();
   $_POST['image'] = $config['upload_path'].$fileInfo['file_name'];
   $this->thumbImage($config['upload_path'].$fileInfo['file_name']);
  }
 }
 public function thumbImage($source_image,$new_image=null){
  $config = $this->config->item('thumb_image');//参数为config数组标签名
  $config['source_image'] = $source_image;
  $config['new_image'] = $config['thumb_path'].$new_image;
  $this->load->library('image_lib', $config);
  $this->image_lib->initialize($config);//以防万一,文档例子不可行时,加上此句
  $this->image_lib->resize();
 }

你可能感兴趣的:(职场,vi,休闲,thumbImage,uploadImage)