首页 > 解决方案 > 如何将 2 张图片上传到两个不同的文件夹(codeginiter)

问题描述

我有这段代码可以将两张图片上传到文件夹'/uploads'

如何将图像 no2 上传到另一个文件夹?

代码

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|svg' ;
$config['max_size'] = 2048;

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

if (! $this->upload->do_upload('userfile') && !$this->upload->do_upload('userfile2') ) {
    $errors = array('error' => $this->upload->display_errors());
    $post_image= 'noimage.png' ;
    $post_image2= 'noimage.png' ;
} else {
    $data = array('upload_data' => $this->upload->data()) ;
    $post_image= $_FILES['userfile']['name'];
    $post_image2= $_FILES['userfile2']['name'];
}

$this->post_model->create_post($post_image,$post_image2);
redirect('../');

标签: phpcodeigniter

解决方案


使用不同的 $config 路径再次加载 lib:

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

然后上传

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

另一个使用另一个路径的上传。

你也可以使用initialize($config)


推荐阅读