Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 为什么无法从多个字段上载多个文件?_Php_Codeigniter - Fatal编程技术网

Php 为什么无法从多个字段上载多个文件?

Php 为什么无法从多个字段上载多个文件?,php,codeigniter,Php,Codeigniter,我有一张表格。我正试图从Codeigniter中的3个不同输入字段上传3个文件。 三个领域是:保险、许可和注册。 字段中的路径准确地保存在数据库中,但只有一个文件指向文件夹。这三个文件有三个不同的文件夹。注册文件已上载到保险文件夹中。未上载许可证和注册 <?php if (!empty($_FILES['insurance']['name'])) { $path = $_FILES['insurance']['name']; $ext = pathinfo($path, P

我有一张表格。我正试图从Codeigniter中的3个不同输入字段上传3个文件。 三个领域是:保险、许可和注册。 字段中的路径准确地保存在数据库中,但只有一个文件指向文件夹。这三个文件有三个不同的文件夹。注册文件已上载到保险文件夹中。未上载许可证和注册

<?php
if (!empty($_FILES['insurance']['name'])) {
    $path = $_FILES['insurance']['name'];
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $rand = 'ins_' . rand(1, 500) . rand(500, 1000) . rand(1, 500);
    $config['upload_path'] = BASEPATH . "../images/insurance/";
    $config['allowed_types'] = '*';
    $config['file_name'] = $rand;
    $this->load->library('upload', $config);
    $this->upload->overwrite = true;
    $this->upload->do_upload('insurance');
    $data = $this->upload->data();
    $_POST['insurance'] = $this->config->base_url() . "images/insurance/" . $rand . '.' . $ext;
} else{
    echo "Error in uploading Insurance Photo";
}

if (!empty($_FILES['permit']['name'])) {
    $path = $_FILES['permit']['name'];
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $rand = 'pmt_' . rand(1, 500) . rand(500, 1000) . rand(1, 500);
    $config['upload_path'] = BASEPATH . "../images/permit/";
    $config['allowed_types'] = '*';
    $config['file_name'] = $rand;
    $this->load->library('upload', $config);
    $this->upload->overwrite = true;
    $this->upload->do_upload('permit');
    $data = $this->upload->data();
    $_POST['permit'] = $this->config->base_url() . "images/permit/" . $rand . '.' . $ext;
} else{
    echo "Error in uploading Permit Photo";
}

if (!empty($_FILES['registration']['name'])) {
    $path = $_FILES['registration']['name'];
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $rand = 'reg_' . rand(1, 500) . rand(500, 1000) . rand(1, 500);
    $config['upload_path'] = BASEPATH . "../images/registration/";
    $config['allowed_types'] = '*';
    $config['file_name'] = $rand;
    $this->load->library('upload', $config);
    $this->upload->overwrite = true;
    $this->upload->do_upload('registration');
    $data = $this->upload->data();
    $_POST['registration'] = $this->config->base_url() . "images/registration/" . $rand . '.' . $ext;
} else{
    echo "Error in uploading Registration Photo";
}
?>
这是上传的控制器代码

<?php
if (!empty($_FILES['insurance']['name'])) {
    $path = $_FILES['insurance']['name'];
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $rand = 'ins_' . rand(1, 500) . rand(500, 1000) . rand(1, 500);
    $config['upload_path'] = BASEPATH . "../images/insurance/";
    $config['allowed_types'] = '*';
    $config['file_name'] = $rand;
    $this->load->library('upload', $config);
    $this->upload->overwrite = true;
    $this->upload->do_upload('insurance');
    $data = $this->upload->data();
    $_POST['insurance'] = $this->config->base_url() . "images/insurance/" . $rand . '.' . $ext;
} else{
    echo "Error in uploading Insurance Photo";
}

if (!empty($_FILES['permit']['name'])) {
    $path = $_FILES['permit']['name'];
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $rand = 'pmt_' . rand(1, 500) . rand(500, 1000) . rand(1, 500);
    $config['upload_path'] = BASEPATH . "../images/permit/";
    $config['allowed_types'] = '*';
    $config['file_name'] = $rand;
    $this->load->library('upload', $config);
    $this->upload->overwrite = true;
    $this->upload->do_upload('permit');
    $data = $this->upload->data();
    $_POST['permit'] = $this->config->base_url() . "images/permit/" . $rand . '.' . $ext;
} else{
    echo "Error in uploading Permit Photo";
}

if (!empty($_FILES['registration']['name'])) {
    $path = $_FILES['registration']['name'];
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $rand = 'reg_' . rand(1, 500) . rand(500, 1000) . rand(1, 500);
    $config['upload_path'] = BASEPATH . "../images/registration/";
    $config['allowed_types'] = '*';
    $config['file_name'] = $rand;
    $this->load->library('upload', $config);
    $this->upload->overwrite = true;
    $this->upload->do_upload('registration');
    $data = $this->upload->data();
    $_POST['registration'] = $this->config->base_url() . "images/registration/" . $rand . '.' . $ext;
} else{
    echo "Error in uploading Registration Photo";
}
?>

这里是风景

<div class="form-group">
    <div class="col-md-12">
        <label class="control-label col-md-4">Insurance Document</label>
        <div id="email-input-wrapper"  class="controls col-sm-6 col-md-8">
            <input class="edit-file" placeholder="Choose Insurance File" disabled="disabled" />
            <div class="fileUpload btn btn-primary">
                <span>Upload Photo</span>
                <input  id="edituploadBtn" type="file"  name="insurance" class="upload" />
            </div>
            <br/>
            <img id="myImgedit" style="width: 100px;height: 100px" src="../images/insurance/no-image.jpg" alt="your image" />
            <?php if (!empty($post['insurance'])) { ?>
                <div id="image-div">
                    <img id="img" src="<?php echo $post['insurance'] ?>" style="height: 100px;width: 100px"/>
                </div>
            <?php } else {
                ?>
                <img id="myno_img" style="width: 100px;height: 100px" src="../images/insurance/no-image.jpg" alt="your image" />
            <?php }
            ?>
        </div>
    </div>
</div>

<div class="form-group">
    <div class="col-md-12">
        <label class="control-label col-md-4">Permit Document</label>
        <div id="email-input-wrapper"  class="controls col-sm-6 col-md-8">
            <input class="edit-file1" placeholder="Choose Permit File" disabled="disabled" />
            <div class="fileUpload btn btn-primary">
                <span>Upload Photo</span>
                <input  id="edituploadBtn1" type="file"  name="permit" class="upload" />
            </div>
            <br/>
            <img id="myImgedit1" style="width: 100px;height: 100px" src="../images/permit/no-image.jpg" alt="your image" />
            <?php if (!empty($post['permit'])) { ?>
                <div id="image-div1">
                    <img id="img" src="<?php echo $post['permit'] ?>" style="height: 100px;width: 100px"/>
                </div>
            <?php } else {
                ?>
                <img id="myno_img1" style="width: 100px;height: 100px" src="../images/permit/no-image.jpg" alt="your image" />
            <?php }
            ?>
        </div>
    </div>
</div>

<div class="form-group">
    <div class="col-md-12">
        <label class="control-label col-md-4">Registration Document</label>
        <div id="email-input-wrapper"  class="controls col-sm-6 col-md-8">
            <input class="edit-file2" placeholder="Choose Registration File" disabled="disabled" />
            <div class="fileUpload btn btn-primary">
                <span>Upload Photo</span>
                <input  id="edituploadBtn2" type="file"  name="registration" class="upload" />
            </div>
            <br/>
            <img id="myImgedit2" style="width: 100px;height: 100px" src="../images/registration/no-image.jpg" alt="your image" />
            <?php if (!empty($post['registration'])) { ?>
                <div id="image-div2">
                    <img id="img" src="<?php echo $post['registration'] ?>" style="height: 100px;width: 100px"/>
                </div>
            <?php } else {
                ?>
                <img id="myno_img2" style="width: 100px;height: 100px" src="../images/registration/no-image.jpg" alt="your image" />
            <?php }
            ?>
        </div>
    </div>
</div>

保险单据
上传照片

“style=”高度:100px;宽度:100px“/> 许可证文件 上传照片
“style=”高度:100px;宽度:100px”/> 注册文件 上传照片
“style=”高度:100px;宽度:100px“/>
您需要使用
$config
初始化上载库,而不是再次加载。您只加载一次上载库,不进行任何配置,然后每次使用配置初始化它

$this->load->library('upload');
// (stuff for first file)
$this->upload->initialize($config);
// (stuff for second file)
$this->upload->initialize($config);
// (...)

表格标签在哪里?