php – 如何在codeigniter 3.0.1中上传多个文件

前端之家收集整理的这篇文章主要介绍了php – 如何在codeigniter 3.0.1中上传多个文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在codeigniter 3.0.1中上传多个文件.在stackoverflow中有类似的问题和解决方案,但不幸的是,这些问题和解决方案正在帮助解决我正面临的问题.

这是出现的错误消息您没有使用我当前的代码选择要上传文件

视图(addGallery)

<section>
    <h2>Add Gallery</h2>
        <?PHP echo form_open('Newsupload/gallery',['id'=>'news','name'=>'news','method'=>'post','enctype'=>'multipart/form-data']) ?>

        <div class="grp width-50">
            <label for="name">Album Name</label>
            <input type="text" name="name" id="name" value="" placeholder="">
        </div>
        <div class="grp width-100">
            <div id="selectedFiles"></div>
            <input type="file" id="files" name="files[]" multiple size="20"><br/>
        </div>
        <?PHP if (isset($error)) {
            echo $error;
        } ?>
        <grp class="grp width-100">
            <button>Add</button>
        </grp>
    </form>
</section>

控制器(画廊)

public function gallery()
{

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

    $files = $_FILES;
    $cpt = count($_FILES['files']['name']);
    for($i=0; $i<$cpt; $i++)
    {           
        $_FILES['files']['name']= $files['files']['name'][$i];
        $_FILES['files']['type']= $files['files']['type'][$i];
        $_FILES['files']['tmp_name']= $files['files']['tmp_name'][$i];
        $_FILES['files']['error']= $files['files']['error'][$i];
        $_FILES['files']['size']= $files['files']['size'][$i];    

        $this->upload->initialize($this->set_upload_options());
        // $this->upload->do_upload('files[]');
        if (!$this->upload->do_upload('files[]'))
        {  
            $error =['error' => $this->upload->display_errors()];
            $this->load->view('admin/addGallery',$error);
        }
    }
}
public function set_upload_options()
{
    $config['upload_path'] = getcwd().'/upload/';
    $config['allowed_types'] = 'gif|jpg|jpeg|png';
    $config['remove_spaces'] = true;
    return $config;
}
默认情况下,CodeIgniter不支持文件上传.所以你可以使用
这个图书馆 CodeIgniter Multiple Upload Library

猜你在找的PHP相关文章