繁体   English   中英

无法在Codeigniter中上传多个具有不同名称的文件

[英]Can't upload multiple files with different names in codeigniter

我想上传两个具有我给定名称的图像

 $config['upload_path'] = '/path/to/file';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '0';
        $config['file_name'] ='logo1_'.$_POST['name'];
        $config['max_width']  = '0';
        $config['max_height']  = '0';
        $this->load->library('upload', $config);
        if ( ! $this->upload->do_upload('image1'))
        {...}
        else
        {
            $data = $this->upload->data();
        }
$config2['upload_path'] = '/path/to/file';
        $config2['allowed_types'] = 'gif|jpg|png';
        $config2['max_size'] = '0';
        $config2['file_name'] = 'logo2_'.$_POST['name'];
        $config2['max_width']  = '0';
        $config2['max_height']  = '0';
        $this->load->library('upload', $config2);
        if ( ! $this->upload->do_upload('image2'))
        {...}
        else
        {
            $data = $this->upload->data();
         }

我的第一张图片正确地保存在我的文件夹中,名称为logo1_myname但是我的第二张图片却没有另存为logo2_myname而是另存为logo1_myname1我的代码有什么问题?

更改

$this->load->library('upload', $config2);

$this->upload->initialize($config2);

由于该类已经加载,因此codeigniter不会再次加载它。

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM