0

我的代码有问题,我尝试上传 csv 文件,几天前它还在工作,但是当我今天早上再试一次时。它不起作用。错误提示“不允许您尝试上传的文件类型。”。

好吧,我使用 codeigniter 和 csvimport 作为库。不知道有没有这个效果。有关其他信息,几天前我在尝试第二次上传之前更新了 wamp 服务器。

我的控制器代码:

public function tambahsoal(){

		$config['upload_path'] = './upload/';
		$config['allowed_types'] = 'csv';
		$config['max_size'] = 1000;

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

		if(!$this->upload->do_upload()){
			$data['error'] = $this->upload->display_errors();
			$this->load->view('dosen/hasilup',$data);
		}else{
			$file_data=$this->upload->data();
			$file_path='./upload/'.$file_data['file_name'];
               //bla bla i code again for get everthing in my csv file.
		}
		
		
	}

结果将处于 if 条件。“您尝试上传的文件类型不被允许。”

谢谢。

4

1 回答 1

0

我注意到你$this->upload->initialize($config);的代码中有。

请删除它。因为 $config 已经传递给你$this->load->library('upload',$config);,所以不需要再次初始化它。

public function tambahsoal(){

        $config['upload_path'] = './upload/';
        $config['allowed_types'] = 'csv';
        $config['max_size'] = 1000;

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

        if(!$this->upload->do_upload()){
            $data['error'] = $this->upload->display_errors();
            $this->load->view('dosen/hasilup',$data);
        }else{
            $file_data=$this->upload->data();
            $file_path='./upload/'.$file_data['file_name'];
               //bla bla i code again for get everthing in my csv file.
        }


    }
于 2016-02-24T02:24:01.683 回答