【问题标题】:csv import. the file type you are attempting to upload is not allowed..csv 导入。不允许您尝试上传的文件类型。
【发布时间】:2016-06-06 02:44:23
【问题描述】:

我的代码有问题,我尝试上传 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);,因为您已经在$this->load->library('upload',$config);上声明了$config

标签: php codeigniter localhost csv-import


【解决方案1】:

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


    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-18
    • 2012-04-06
    • 2012-04-22
    • 2011-11-21
    • 2011-06-08
    • 2014-12-30
    • 1970-01-01
    • 2019-05-20
    相关资源
    最近更新 更多