如何使用Codeigniter上传两个不同文件夹中的图像和视频

问题描述:

我在codeignite中更新鲜,我想将图像和视频上传到图像和视频文件夹中。但图像和视频上传到同一个文件夹。如何使用Codeigniter上传两个不同文件夹中的图像和视频

我试了很多次,如果条件,但没有什么改变。

请帮忙解决这个问题。

这里是我的代码: -

<?php 

class Upload extends CI_Controller { 

    function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper(array('form', 'url')); 
    } 

    function index() 
    { 
     $data['data'] = ""; 
     $data['content']=$this->load->view('cmsblock/cmsblock',$data,TRUE); 
     $this->load->view('includes/main',$data); 
    } 

    function do_upload() 
    {  


     foreach ($_FILES as $key => $value) { 

      if (!empty($value['tmp_name'])) { 


       if($key == "file1") { 

        $config['upload_path'] = 'uploads'; 
        $config['allowed_types'] = 'mp4|3gp|gif|jpg|png|jpeg|pdf'; 
        $config['max_size']=''; 
        $config['max_width']='200000000'; 
        $config['max_height']='1000000000000'; 
        $this->load->library('upload',$config); 
        if (! $this->upload->do_upload($key)) { 
        $error = array('error' => $this->upload->display_errors()); 
        //failed display the errors 
        } else { 

         $data = array('upload_data' => $this->upload->data()); 
         $this->load->view('cmsblock/success', $data); 

        } 
       } 
       if($key == "file2") { 

        $config11['upload_path'] = 'videos'; 
        //$config11['upload_path'] = 'uploads'; 
        $config11['allowed_types'] = 'mp4|3gp|gif|jpg|png|jpeg|pdf'; 
        $config11['max_size']=''; 
        $config11['max_width']='200000000'; 
        $config11['max_height']='1000000000000'; 
        $this->load->library('upload',$config11); 
        if (! $this->upload->do_upload($key)) { 
        $error = array('error' => $this->upload->display_errors()); 
        //failed display the errors 
        } else { 

         $data = array('upload_data' => $this->upload->data()); 
         $this->load->view('cmsblock/success', $data); 

        } 
       }    



      } 
     } 
    } 
} ?> 

这里是我的HTML文件中的代码:的

<?php echo form_open_multipart('admin/upload/do_upload');?> 

<input type="file" name="file1" id="file_1" /> 
<input type="file" name="file2" id="file_2"/> 
<br/><br/> 

<input type="submit" value="upload" /> 

</form> 
+0

如果您提供了[mcve],将会很有用。 – Ivar

+0

没有你的表格html代码,很难决定! – Rifky

使用try

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

代替

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

in if($key == "file2"){... part