【问题标题】:CI upload error, You did not select a file to uploadCI 上传错误,您没有选择要上传的文件
【发布时间】:2014-11-14 16:29:32
【问题描述】:

我已经在这个应用程序中工作了一段时间,但我以前从未遇到过这个错误。 我一直在尝试做多种事情来获得解决方案,例如将 php.ini 中的 post_max_size 修改为 9999M 但没有奏效,所以我不知道错误在哪里或我需要做什么。

            $nextId = uniqid();
            $config['file_name'] = $nextId;
            $config['overwrite'] = TRUE;
            $config['upload_path'] = '/uploads/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg';
            print_r($_FILES);
            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload() ) {
                $data['msg'] = '     Foto '.$this->upload->display_errors();
                $this->data['contenido'] = $this->load->view($this->mainView.'/nuevo_view', $data, TRUE);
                $this->load->view('templates/main_template', $this->data);
                return;
            } else {
                echo 'success'; }

这是表格:

<form method="post" class="form-horizontal" action="<?php echo $this->router->class.'/nuevo'; ?>" enctype="multipart/form-data">
<div class="form-group">
        <label for="" class="col-sm-2 control-label">Imagen</label>
        <input type="file" id="imagen" name="imagen" required>
        <span class="help-block m-b-none">480px Ancho por 230px Alto (Recomendado)</span>
    </div>

就像代码显示的那样,我打印 $_FILE 以了解它是否在数组中;这是输出:

Array ( [imagen] => Array ( [name] => dropdown.9.png [type] => image/png [tmp_name] => /Applications/MAMP/tmp/php/php7WJQok [error] => 0 [size] => 1182 ) )

【问题讨论】:

    标签: php codeigniter file-upload


    【解决方案1】:

    do_upload 函数正在寻找一个名为“userfile”的字段,除非您更改它...

    试试这个,看看是否有效;

    $this->upload->do_upload('imagen')
    

    【讨论】:

    【解决方案2】:

    file uploader CI 类的链接

    如前所述,do_upload() 函数要求默认文件输入字段为 userfile

    要么将文件输入字段编辑为userfile,要么使用,

    $this->upload->do_upload('imagen')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多