<?php
//详细代码以下,在upload_img() 调用$this->create_thumbnail(); 和$this->img_resize(); 时后者的会失效,两个函数的前后那个函数调用失效啊,都是后边哪个函数可以调用,不知道原因,昐各位高手指点,多谢。
class Upload extends Controller {
function Upload()
{
parent::Controller();
$this->load->library('image_lib');
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '2048';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
echo $this->upload->display_errors();
}else {
$file_info = $this->upload->data();
$this->create_thumbnail($file_info['file_name'],$file_info['image_width'],$file_info['image_height']);
$this->img_resize($file_info['file_name'],$file_info['image_width'],$file_info['image_height']);
$data_img['goods_image'] = $file_info['file_name'];
$data_img['thumb_image'] = 'thumb/'.$file_info['raw_name'] . '_thumb' . $file_info['file_ext'];
// return $data_img;
//print_r($data_img);
$this->load->view('upload_success', $data_img);
}
}
//缩略图
private function create_thumbnail($file_name,$image_width,$image_height) {
$set_thumb_width = 100;
$set_thumb_height = 75;
$config['image_library'] = 'gd2';
$config['source_image'] ='./uploads/' . $file_name;
$config['new_image'] = './uploads/thumb/' . $file_name; //没有生产缩略图
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
if($image_width > $set_thumb_width or $image_height > $set_thumb_height){
$config['width'] = $set_thumb_width;
$config['height'] = $set_thumb_height;
}
$this->load->library('image_lib', $config); ////////加载
if(!$this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
unset($config);
$this->image_lib->clear();
}
//调整图像大小
function img_resize($file_name,$image_width,$image_height) {
$set_width = 200;
$set_height = 200;
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/' . $file_name;
$config['new_image'] = './uploads/image/' . $file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
if($image_width > $set_width or $image_height > $set_height){
$config['width'] = $set_width;
$config['height'] = $set_height;
}
//$this->load->library('image_lib', $config);
$this->image_lib->initialize($config); ////////加载
if(!$this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
unset($config);
$this->image_lib->clear();
}
}
没有报错误,在指定文件夹里面没有生产缩略图。什么原因呢? |