/* * 文件上传 * @param $upload_path 文件上传路径 * @param $formpic 表单name属性名称 */ private function doUpload($upload_path,$formpic){ //配置 //设置文件上传的路径 $config['upload_path'] = $upload_path; //限制文件上传的类型 $config['allowed_types'] = 'gif|jpg|png|jpeg'; //限制文件上传的大小 $config['max_size'] = '2048'; //设置文件上传的路径 $config['file_name'] = time() . mt_rand(1000,9999); //载入上传类 $this->load->library('Upload', $config); //执行上传 $status = $this->upload->do_upload($formpic); } /** * 生成缩略图 * @param $path 原图的本地路径 * @param $newPath 缩略图存储路径 */ private function dealthumb($path,$newPath,$width,$height){ $config['image_library'] = 'gd2'; $config['source_image'] = $path; $config['new_image'] = $newPath; $config['create_thumb'] = TRUE; //生成的缩略图将在保持纵横比例 在宽度和高度上接近所设定的width和height $config['maintain_ratio'] = TRUE; $config['width'] = $width; $config['height'] = $height; //载入图像处理类库 $this->load->library('Image_lib'); $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); }