【问题标题】:$this->upload->do_upload(); not working$this->upload->do_upload();不工作
【发布时间】:2016-05-15 11:10:53
【问题描述】:
function do_upload(){//This is my controller//
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['overwrite'] = true; 
    //$config['max_size']   = '100';
    //$config['max_width']  = '1024';
    //$config['max_height']  = '768';
    $this->load->library('upload');
    $this->upload->initialize($config);
    $this->upload->do_upload();
    if (!$this->upload->do_upload()){//I also found out that this is the part that is not working
        echo "failed!";
    }
    else{
        $this->upload->data();
        echo "success!";
    }
}

“我已经尝试了一些教程来完成这项工作,但似乎对这个没有任何帮助”

【问题讨论】:

  • 检查您的表单 enctype 属性是否设置。 w3schools.com/tags/att_form_enctype.asp
  • 我已经检查过了,这是我的表单代码
  • 你是否收到了失败的消息然后试试这个 print_r( $this->upload->display_errors());您也可以将文件上传字段名称作为参数传递给 do_upoad('userfile') 方法。示例 userfile 是表单字段名称
  • 这是错误消息先生“上传目标文件夹似乎不可写。”
  • 如果您在应用程序之外有文件夹,请在此处为前端控制器路径提供 FCPATH 的完整路径 FCPATH.'uploads/' 像这样更改它

标签: file codeigniter file-upload


【解决方案1】:

这可能是“上传”目录中的文件权限问题。为上传文件夹设置适当的可写权限。

【讨论】:

    【解决方案2】:
     'upload_path' => $image_path,
     'allowed_types' => "gif|jpg|png|jpeg",
     'overwrite' => TRUE,
     'max_size' => "2048000",
     'max_height' => "1000",
     'max_width' => "2000"
    

    试试这个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 2016-09-03
      • 2017-05-26
      相关资源
      最近更新 更多