CSV 导入.您尝试上传的文件类型是不允许的


csv import. the file type you are attempting to upload is not allowed.

我的代码有问题,我尝试上传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 条件下。"您尝试上传的文件类型是不允许的。"

谢谢。

我注意到你的代码中有$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.
        }

    }