【问题标题】:Upload issue in Codeigniter在 Codeigniter 中上传问题
【发布时间】:2015-04-11 19:27:05
【问题描述】:

这是html部分:

 <form action ="<?php echo base_url(); ?>home/register_doctor" method ="POST" enctype="multipart/form-data" accept-charset="utf-8">
...
<input id="file-0" class="file" type="file" multiple data-min-file-count="1" name = "avatar" >
...
</form>

这是控制器部分:

    public function register_doctor(){
       ...
        if ($this->form_validation->run() == FALSE){
           ....
        }else{
          $this->do_upload();
        }
    }
    function do_upload(){
        $config['upload_path'] = './uploads/doctors/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload', $config);
        $this->upload->do_upload('avatar');
        $x = $this->upload->display_errors();
        var_dump($x);
    }

这条消息的结果是:You did not select a file to upload.。有人可以帮我吗?

更新这是文件夹结构:

更新这是我的 PHP.INI 文件:CLICK HERE

【问题讨论】:

  • 这是 $_FILES 的 var_dump 的结果:array(0) { } 我把它放在函数 do_upload 上
  • 就是:php.ini中的upload_max_filesize=512M
  • 您尝试上传的文件大小是多少?
  • img 的大小为:5.51 KB(5,651 字节)。这是我在帖子上上传的图片
  • 我在我的帖子上上传了我的 php ini 文件。请检查一下。我在没有 ajax 的情况下上传

标签: php codeigniter upload


【解决方案1】:

问题出在配置中

    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

应该如下

    $config['max_size'] = 100;
    $config['max_width']  = 1024;
    $config['max_height']  = 768;

希望对你有帮助

【讨论】:

  • 我得到了同样的结果:您没有选择要上传的文件。 :(
  • 清除缓存并确保您的目录路径为'./uploads/doctors'
  • var_dump($_FILES); 的结果不奇怪吗?是数组(0){}?在我的功能中?
  • 检查您的客户端代码。提交时可能存在使您选择的文件为空的任何代码
【解决方案2】:

替换你的&lt;form action ="&lt;?php echo base_url(); ?&gt;home/register_doctor" method ="POST" enctype="multipart/form-data" accept-charset="utf-8"&gt;

<?php echo  form_open_multipart('home/register_doctor'); ?>

【讨论】:

    猜你喜欢
    • 2013-04-20
    • 2013-07-07
    • 2012-01-09
    • 2011-08-04
    • 1970-01-01
    • 2021-08-27
    • 2013-10-20
    • 2015-11-23
    相关资源
    最近更新 更多