如何使用CodeIgniter上传具有多个输入的多个文件

时间:2016-03-29 05:33:58

标签: codeigniter

plaese帮我亲爱的,
我有一个表单,我想上传具有多个输入的文件(employee_name,resume,offer_letter,joined_letter)      使用codeigniter。     我的表格如下:

     <form class="form-horizontal form-bordered" action="<?php echo base_url('save_employee/');?>" enctype="multipart/form-data" method="POST">

        <div class="form-group">
                <label for="exampleInputEmail1">Employee Image</label>
                <input type="file" class="form-control" name="employee_name">
              </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Resume/CV</label>
                <input type="file" class="form-control" name="resume">
              </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Offer letter</label>
                <input type="file" class="form-control" name="offer_letter">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Joining Letter</label>
                <input type="file" class="form-control" name="joining_letter">
            </div>
        </form

1 个答案:

答案 0 :(得分:0)

将此项放入您的控制器中这需要四个字段来上传文件

public function Add() {
        $data                          =        array();
        $config                        =        array(
        'upload_path' => 'upload',
        'allowed_types' => 'gif|jpg|png',
        'max_size' => 250,
        'max_width' => 1920,
        'max_heigh' => 1080,
    );
    $this->load->library('upload', $config);

    if($this->input->post('Submit'))    {
        $file_data                  =       $this->upload->data();
        $data['cnic_img']           =       $file_data['file_name'];

        $file_data                  =       $this->upload->data();
        $data['domcie_img']         =       $file_data['file_name'];

        $file_data                  =       $this->upload->data();
        $data['profile_img']        =       $file_data['file_name'];

        $file_data                  =       $this->upload->data();
        $data['report_img']         =       $file_data['file_name'];
         $lat_id                    =       $this->your_model->save($data);
        }
        $this->load->View('your_template');
     }

把它放在你的模型中

function save($data){
    $this->db->insert('your_table', $data);
    return $this->db->insert_id();
   }

这是您的观点

<div class="portlet-body form">
<!-- BEGIN FORM-->
<?php echo $this->upload->display_errors(''); ?>
<form class="form-horizontal" action="" <?php echo form_open_multipart();?>
<div class="form-group">
                                    <label for="CNIC Image" class="col-md-3 control-label">CNIC Image:</label>
                                    <div class="col-md-9">
                                        <input type="file" id="cnic_img" name="cnic_img">
                                        <p class="help-block">
                                             Upload CNIC image Here.
                                        </p>
                                    </div>
                                </div>
                            </div>
                    </div>
                    <div class="portlet-body form">
                            <div class="form-body">

                                                                    <div class="form-group">
                                    <label for="Domicile Image" class="col-md-3 control-label">Domicile Image:</label>
                                    <div class="col-md-9">
                                        <input type="file" id="domcie_img" name="domcie_img">
                                        <p class="help-block">
                                                Upload Domicile Image Here.
                                        </p>
                                    </div>
                                </div>
                            </div>
                    </div>
                    <div class="portlet-body form">
                            <div class="form-body">

                                                                    <div class="form-group">
                                    <label for="Domicile Image" class="col-md-3 control-label">Profile Image:</label>
                                    <div class="col-md-9">
                                        <input type="file" id="profile_img" name="profile_img" >
                                        <p class="help-block">
                                                 Upload Profile Image Here.
                                        </p>
                                    </div>
                                </div>
                            </div>
                    </div>
                    <div class="portlet-body form">
                            <div class="form-body">

                                                                    <div class="form-group">
                                    <label for="Domicile Image" class="col-md-3 control-label">Police validation Report:</label>
                                    <div class="col-md-9">
                                        <input type="file" id="report_img" name="report_img">
                                        <p class="help-block">
                                                 Upload Police Validation Report Here.
                                        </p>
                                    </div>
                                </div>
                            </div>
                    </div>