【问题标题】:how to upload multiple file from a single form in codeigniter [duplicate]如何在codeigniter中从单个表单上传多个文件[重复]
【发布时间】:2013-04-01 04:33:52
【问题描述】:

谁能帮我从一个表单上传多个文件。如果可能,请举一些例子。我已经通过互联网浏览了几个地方,但没有找到任何解决方案。下面是我的上传功能模型代码,它适用于单次上传,但不适用于从单个表单进行多次上传。

function upload(){
     $config[$a]=array(
        'allowed_types'=>'xlsx',
        'upload_path'=>  $this->gallery_path,
        'overwrite'=>true,
        'max_size'=>2000,
    );
     $this->load->library('upload',$config);
    $this->upload->do_upload();

}

提前致谢。

【问题讨论】:

  • $config[$a] 中的$a 是什么?
  • 对不起,我的错。忽略 $config[$a],它将是 $config

标签: php codeigniter


【解决方案1】:

试试这个:

function do_upload()
{
    foreach ($_FILES as $index => $value)
    {
        if ($value['name'] != '')
        {
            $this->load->library('upload');
            $this->upload->initialize($this->set_upload_options());

            //upload the image
            if ( ! $this->upload->do_upload($index))
            {
                $error['upload_error'] = $this->upload->display_errors("<span class='error'>", "</span>");

                //load the view and the layout
                $this->load->view('pages/uploadform', $error);

                return FALSE;
            }
            else
            {

                 $data[$key] = array('upload_data' => $this->upload->data());

                 $this->load->view('pages/uploadsuccess', $data[$key]);


            }
        }
    }

}

//here put your rules
private function set_upload_options()
{   
    //upload an image options
    $config = array();

    $config['upload_path']   = FCPATH.'public/uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['encrypt_name']  = TRUE;
    $config['max_width']     = '2000';
    $config['max_height']    = '1500';
    $config['max_size']      = '2048';

    return $config;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-28
    • 2020-02-01
    • 2014-08-13
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2019-07-19
    • 2018-08-01
    相关资源
    最近更新 更多