php - 使用 codeigniter 上传时为 "did not select a file to upload"

标签 php codeigniter file-upload

我正在尝试上传图片,但它总是提示“您没有选择要上传的文件。”

我的 Controller

function add()
{

        $thedate=date('Y/n/j h:i:s');
        $replace = array(":"," ","/");
        $newname=str_ireplace($replace, "-", $thedate);

        $config['upload_path'] = './upload/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['file_name']=$newname;
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

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

        $this->form_validation->set_rules('title','title','trim|required');
        $this->form_validation->set_rules('description','Description','trim|required');
        $image1=$this->input->post('image');


     if ($this->form_validation->run()==FALSE){

            $this->addview();   

            return false;

        }


      if (!$this->upload->do_upload($image1)) {

        $error = array('error' => $this->upload->display_errors());
        $this->load->view('upload_error', $error);


         }

       else {
        $mage=$this->upload->do_upload($image1);

            $data =array(
            'title'=>$this->input->post('title'),
            'descrip'=>$this->input->post('description'),

            'image' => $mage['file_name']

    );  


            $this->load->model('member_functions');

            $q=$this->member_functions->insert($data);
    }}

所有文件要求和文件权限都已设置,但我仍然收到该错误。有人可以告诉我我做错了什么吗

最佳答案

$this->upload->do_upload() 函数的参数应该是表单字段的名称。 (如果您不带参数调用它,将使用 userfile)。在您的情况下,它似乎应该是“图像”。而不是:

$image1=$this->input->post('image');

应该是:

$image1='image';

关于php - 使用 codeigniter 上传时为 "did not select a file to upload",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7457152/

相关文章:

php - Codeigniter,从分解的字符串中获取值

angularjs - Protractor - 如何在测试用例中使用 ng-file-upload 上传文件而不更改代码?

基于 PHP 的搜索框架

php - 带有 mysql 数据提交的表单设计器应用程序

php - MVC 框架中的模型应该有多粗粒度?

javascript - 如何使用 AngularJS 上传文件?

spring - 文件上传在 Primefaces 中不起作用

php - 自定义 Laravel API 验证响应

php - 我可以将变量值添加到 php 中传递的函数参数吗?

javascript - TypeError : oTable. fnReloadAjax 不是函数 - DataTables