多个图像上传codeigniter与不同的输入标签

时间:2016-09-22 11:22:36

标签: php codeigniter

我有以下codeigniter代码,这取决于导演的数量。意味着如果我的任何董事都是2,那么下面的代码将是2次。所以我用了唯一的id。我想一键上传所有图像( 1个1个图像的1个导演)。他们的名字应该以 director1 _

开头
<div class="row">
                            <h5 style="padding: 0 15px;">Details for Director 1</h5>
                            <div class="form-group col-md-4">
                                <label>Full Name</label>
                                <input type="hidden" name="director[0][cid]" value="9">
                                <input type="text" class="form-control" name="director[0][name]" required="required" placeholder="Enter Your Full Name" autocomplete="off">
                            </div>
                            <div class="form-group col-md-4">
                                <label>Father's Name</label>
                                <input type="text" class="form-control" name="director[0][fname]" required="" placeholder="Enter Father's Name">
                            </div>
                            <div class="form-group col-md-4">
                                <label>Address</label>
                                <input type="text" class="form-control" name="director[0][address]" placeholder="Enter Address">
                            </div>
                            </div>
<div class="row">
                            <div class="form-group col-md-4">
                                <label>Color Photograph</label>
                                <input type="file" class="form-control" name="image[0][photo]">
                            </div>
                            <div class="form-group col-md-4">
                                <label>PAN Card</label>
                                <input type="file" class="form-control" name="image[0][pan]">
                            </div>
                            <div class="form-group col-md-4">
                                <label>Address Proof</label>
                                <input type="file" class="form-control" name="image[0][address]">
                            </div>
                            </div>

在我的控制器中,我使用了以下代码

function upload_files($path, $title, $files)
{
    $config = array(
        'upload_path'   => $path,
        'allowed_types' => 'jpg|gif|png',
        'overwrite'     => 1,                       
    );

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

    $images = array();

    foreach ($files['image'] as $key => $image) {
        $_FILES['images[]']['name']= $files['name'][$key];
        $_FILES['images[]']['type']= $files['type'][$key];
        $_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
        $_FILES['images[]']['error']= $files['error'][$key];
        $_FILES['images[]']['size']= $files['size'][$key];

        $fileName = $title .'_'. $image;

        $images[] = $fileName;

        $config['file_name'] = $fileName;

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

        if ($this->upload->do_upload('images[]')) {
            $this->upload->data();
        } else {
            return false;
        }
    }

    return $images;
}

但是,它不起作用。任何帮助将不胜感激

0 个答案:

没有答案