在 codeigniter 控制器上上传文件的表单上的空数据

Empty data on form that uploads a file on codeigniter controller

我正在尝试使用此表单上传文件

<form action="/ajax/images/store_image" method="post" enctype="multipart/form-data">
        <div class="form-group">
          <label for="exampleFormControlFile1">Selecciona una imagen</label>
           <input type="file" class="form-control-file" id="exampleFormControlFile1">
           <input type="hidden" name="{{ csrf_name }}" value="{{ csrf_hash }}">
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-primary">Submit</button>
        </div>
</form>

这是监听请求的 codeigniter 控制器

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . 'controllers/Common/Backend_Controller.php';

/**
 * This class provides all the methods & functionallity of public "Batch operations" page.
 */
class Images extends Backend_Controller {

    public function storeImage(){
        var_dump($_POST);
    }
}

它只显示 $_POST 内容..而且总是空的

您不能使用 $_POST 转储多部分表单数据。你必须使用 $_FILES.

NOTE: name attribute is missing from the file input. The name attribute is mandatory for submitting the form data.