Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上载带有2个独立输入字段的文件_Php_Codeigniter_File Upload - Fatal编程技术网

Php 上载带有2个独立输入字段的文件

Php 上载带有2个独立输入字段的文件,php,codeigniter,file-upload,Php,Codeigniter,File Upload,有一个表单,用户输入全名、年龄、个人资料图片、文档并提交。我设法让表单使用一个文件上传,但我找不到一个合适的方法从两个不同的输入上传文件 下面是我的表格 HTML <form enctype="multipart/form-data" action="" method="post"> <div class="form-group"> <label>Name</label>

有一个表单,用户输入全名、年龄、个人资料图片、文档并提交。我设法让表单使用一个文件上传,但我找不到一个合适的方法从两个不同的输入上传文件

下面是我的表格

HTML

<form enctype="multipart/form-data" action="" method="post">

           <div class="form-group">
                <label>Name</label>
                <input type="text" class="form-control" name="full_name"/>
            </div>
           <div class="form-group">
                <label>Age</label>
                <input type="text" class="form-control" name="age"/>
            </div>
           <div class="form-group">
                <label>Choose Profile pic</label>
                <input type="file" class="form-control" name="userfile1"/>
            </div>

            <div class="form-group">
                <label>Choose Document</label>
                <input type="file" class="form-control" name="userfile2"/>
            </div>
            <div class="form-group">
                <input class="form-control" type="submit" name="upload" value="UPLOAD"/>
            </div>
        </form>

名称
年龄
选择个人资料图片
选择文档
PHP

if ($this->input->post('upload'))
        {

            $config['upload_path']          = './uploads/';
            $config['allowed_types']        = 'gif|jpg|png|doc|docx|pdf';
            $config['max_size']             = 10000;
            $config['max_width']            = 3000;
            $config['max_height']           = 3000;

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

            if ( !$this->upload->do_upload('userfile1'))
            {


                $this->session->set_flashdata('status','<div class="alert alert-danger alert-style-square">
                                            <p style="text-align:center">There was an error. Try again. '.$this->upload->display_errors().'</p>
                                        </div>');

            }
            else
            {
                $data = array('upload_data' => $this->upload->data());

                $values = array('full_name'=>$this->input->post('full_name'),
                        'age'=>$this->input->post('age'),
                        'profile_image'=>$this->upload->data('file_name'),
                        //'document'=>$this->upload->data('file_name'),
                        'uploaded_date'=>date("Y-m-d H:i:s"));



                var_dump($values);

            }

    }
if($this->input->post('upload'))
{
$config['upload_path']='./uploads/';
$config['allowed_types']='gif | jpg | png | doc | docx | pdf';
$config['max_size']=10000;
$config['max_width']=3000;
$config['max_height']=3000;
$this->load->library('upload',$config);
如果(!$this->upload->do_upload('userfile1'))
{
$this->session->set_flashdata('状态','
出现错误。请重试。“$this->upload->display_errors()。”

'); } 其他的 { $data=array('upload_data'=>$this->upload->data()); $values=array('full\u name'=>$this->input->post('full\u name'), 'age'=>this->input->post('age'), 'profile\u image'=>this->upload->data('file\u name'), //'document'=>this->upload->data('file_name'), “上传日期”=>日期(“Y-m-d H:i:s”); var_dump(价值); } }
非常感谢您的帮助和指导

您可以尝试更改

if ( !$this->upload->do_upload('userfile1'))

这样做需要用户上传两个图像。如果只需要一个图像,您可以尝试将更改为,您可以尝试更改

if ( !$this->upload->do_upload('userfile1'))


这样做需要用户上传两个图像。如果只需要一个图像,您可以尝试将更改为

,谢谢。。。但是我如何分别获得文件名呢?似乎您应该使用
'profile\u image'=>$this->upload->data('userfile1'),
'document'=>$this->upload->data('userfile2'),
谢谢。。。但是如何分别获取文件名呢?似乎您应该使用
'profile\u image'=>$this->upload->data('userfile1'),
'document'=>$this->upload->data('userfile2'),