douchi5822 2013-03-14 16:16
浏览 52

Codeigniter 2.1 - fileupload您没有选择要上传的文件

Model function:

public function file_upload($folder, $allowed_type, $max_size = 0, $max_width = 0, $max_height = 0)
    {
        $folder = $this->path . $folder;

        $files = array();
        $count = 0;

        foreach ($_FILES as $key => $value) :

            $file_name = is_array($value['name']) ? $value['name'][$count] : $value['name'];
            $file_name = $this->global_functions->char_replace($file_name, '_');
                $count++;
                $config = array(
                'allowed_types' => $allowed_type,
                'upload_path'   => $folder,
                'file_name'     => $file_name,
                'max_size'      => $max_size,
                'max_width'     => $max_width,
                'max_height'    => $max_height,
                'remove_spaces' => TRUE
                 );

        $this->load->library('image_lib');
            $this->image_lib->clear();
            $this->load->library('upload');
            $this->upload->initialize($config);

            if (!$this->upload->do_upload($key)) :
                $error = array('error' => $this->upload->display_errors());
            var_dump($error);
                return FALSE;
            else :
                $file = $this->upload->data();
                $files[] = $file['file_name'];
            endif;

        endforeach;

        if(empty($files)):
            return FALSE;
        else:
            return implode(',', $files);
        endif;
    }

This function is working partially. Files are being uploaded to the selected folder, but I am getting this error: You did not select a file to upload. and getting FALSE as a result? What seems to be a problem? (form is using form_open_multipart)

  • 写回答

2条回答 默认 最新

  • douquanzhan0315 2013-03-14 16:31
    关注

    Please make sure that you have this name of your file tag field:

       $key='userfile' //which is name of input type field name
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败