【问题标题】:How to Upload the image and Video in two Different Folder using Codeigniter如何使用 Codeigniter 在两个不同的文件夹中上传图像和视频
【发布时间】:2016-01-13 22:02:48
【问题描述】:

我对 codeignite 比较陌生,我想将图像和视频上传到图像和视频文件夹中。但是图像和视频上传到同一个文件夹中。

我尝试了很多次使用 if 条件,但没有任何改变。

请帮忙解决这个问题。

这是我的代码:-

<?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>

【问题讨论】:

标签: php codeigniter


【解决方案1】:

尝试使用

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

而不是

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

if($key == "file2"){... 部分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-04
    • 2016-11-30
    • 2014-02-20
    • 1970-01-01
    • 2015-01-17
    • 2017-12-15
    • 1970-01-01
    • 2016-12-10
    相关资源
    最近更新 更多