用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4161|回复: 2
收起左侧

[版本 2.x] CI上传多个图片问题

[复制链接]
发表于 2012-7-30 13:44:53 | 显示全部楼层 |阅读模式
本帖最后由 huhe12319 于 2012-7-30 13:46 编辑

当我需要一次上传多张图的时候。
   我是独立调用几次上传图片的函数,每张图片的大小限制不一样。

  当文件执行的时候,都是调用第一张图片的限制大小,后面的图片就上传不了,而且也就第一张图片生成缩略图。

   各位懂的帮忙解决下  

PHP复制代码
 
 
/**
* 功能描述:上传图片
* 参数:$upload_path 上传路径 $allowed_types 文件类型 max_size 文件大小 $max_width 宽  $max_height 高
*       filename 上传文件域 $names 文件名 $thumb 是否生成缩略图 width 缩略图宽 height 缩略图高
* 返回:
*/

if(!function_exists('upload_file'))
{
     function upload_file($filename='',$names='',$upload_path='',$allowed_types='',$max_size=1024,$max_width=0,$max_height=0,$thumb=0,$width=100,$height=75)
     {
        $CI =& get_instance();
        $config['upload_path'] = $upload_path;
        $config['allowed_types'] = $allowed_types;
        $config['max_size'] = $max_size;
        $config['max_width']  = $max_width;
        $config['max_height']  = $max_height;
        $config['file_name'] = $names;
        if(!is_dir($config['upload_path']))
        {
             mkdir($config['upload_path'],0777);
        }
        $CI->load->library('upload', $config);
         
        if(!$CI->upload->do_upload($filename))
        {
           $error = $filename.$CI->upload->display_errors();
                   
           alertLocation($error);          
        }
        else
        {
          $data = $CI->upload->data();          
          $img = $upload_path.'/'.$data['file_name'];    
       
          if($thumb == 1)
          {
              $config['image_library'] = 'gd2';
              $config['source_image'] = $img;
              $config['create_thumb'] = TRUE;
              $config['maintain_ratio'] = TRUE;                  
              $config['width'] = $width;
              $config['height'] = $height;                
              $CI->load->library('image_lib', $config);                
              $CI->image_lib->resize();
              $CI->image_lib->clear();
          }
                           
          if(substr($img,0,7) == 'uploads') $img = '/'.$img;
       
          return $img;        
                                           
        }
       
       
     }
   
}
 
 
复制代码


发表于 2012-7-31 15:42:16 | 显示全部楼层
试试这样初始化上传类

$CI->load->library('upload');
$CI->upload->initialize($config);


发表于 2012-7-31 16:50:48 | 显示全部楼层
上传图片我没有用CI自带的方法,自己写一个,或者百度一个,都可以用的把

本版积分规则