【发布时间】:2011-05-30 12:16:39
【问题描述】:
function upload($path){
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['max_size'] = 2000;
if($path =='profile'){
$config['upload_path'] = '../assets/uploads/avatars';
$config['file_name'] = $this->id;
}
if($path =='company'){
$config['upload_path'] = '../assets/uploads/company';
$config['file_name'] = $this->id.'_company';
}
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
if($path == 'profile'){
$this->db->update('be_user_profiles',array('avatar' => $image_data['file_name']), array('user_id' => $this->id));
}
if($path == 'company'){
$this->db->update('be_user_profiles',array('company_logo' => $image_data['file_name']), array('user_id' => $this->id));
}
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->upload_path,
'maintain_ratio' => true,
'width' => 500,
'height' => 500
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
这是我的上传功能,在$path = 'profile'时可以正常使用,但是在company时,它不会上传到“公司”文件夹...
有什么理由应该这样吗?!我在这里不知所措......这个功能在它进入头像文件夹时有效,但如果它进入公司文件夹......
【问题讨论】:
-
替换 $this->load->library('image_lib', $config);通过 $this->load->library('image_lib'); $this->image_lib->初始化($config);
标签: php codeigniter upload