gpt4 book ai didi

php - Codeigniter 图片上传只会上传到一个目录

转载 作者:行者123 更新时间:2023-12-02 04:14:04 27 4
gpt4 key购买 nike

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->upload->initialize($config);

您可以加载库,然后设置您的配置并调用 initialize 方法。

希望这可以帮助。

关于php - Codeigniter 图片上传只会上传到一个目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4528116/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com