CI上传错误,您没有选择要上传的文件

时间:2014-11-14 16:29:32

标签: php codeigniter file-upload

我已经在这个应用程序中工作了一段时间,但我之前从未遇到此错误。 我一直试图做多个事情来获得解决方案,比如将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 ) )

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

file uploader CI类链接

如上所述 do_upload()函数需要默认文件输入字段为 userfile

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

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