通过codeigniter设置特定大小来上传图像

时间:2014-07-12 03:54:43

标签: codeigniter

我想上传多个带有codeigniter的文件,其要求如下:

  1. 用户可以上传图片的任何宽度和高度
  2. 图像的最大尺寸为10 MB
  3. 上传后,我想获得两张图片。 第一张图片的尺寸是width = 700,height = auto。为第二张图片创建缩略图。它的大小是宽度= 100,高度=自动。
  4. 我想删除原始文件
  5. 有人可以帮助我吗?

    先谢谢。

1 个答案:

答案 0 :(得分:0)

function do_upload()    
{    
$config['upload_path'] = './uploads/';       
$config['allowed_types'] = 'gif|jpg|png';    
$config['max_size']    = '1024*10';    
$this->load->library('upload', $config);        
if ( ! $this->upload->do_upload())       
{    
$error = array('error' => $this->upload->display_errors());    
$this->load->view('upload_form', $error);    
}       
else       
{        
$data=$this->upload->data();    
$this->thumb($data,700,false);        
$this->thumb($data,100,true);       
unlink($data['full_path']);       
$this->load->view('upload_success', $data);      
}      
}             
function thumb($data,$thumb_size,$create_thumb)    
{       
$config['image_library'] = 'gd2';    
$config['source_image'] =$data['full_path'];      
$config['create_thumb'] = $create_thumb;    
$config['maintain_ratio'] = TRUE;    
$config['width'] = $thumb;     
$config['height'] = $thumb;     
$this->load->library('image_lib', $config);    
$this->image_lib->resize();    
}     

供参考[此处]:http://www.tutsmore.com/tutorials/codeigniter-image-upload-with-mysql/