如何删除此错误:不允许您尝试上载的文件类型

时间:2017-10-16 07:36:40

标签: php codeigniter codeigniter-upload

 public function addAppdetails()
    {   $dev_id = $this->sessionStart();

        $this->load->library('form_validation');
        $this->form_validation->set_rules('appname', 'App Name', 'required');
        $this->form_validation->set_rules('platform', 'Platform', 'required');
        //$this->form_validation->set_rules('category','App Category','required');
        $this->form_validation->set_rules('description', 'App Description', 'required');
        //$this->form_validation->set_rules('app_pic','App Pic','required');
        //$this->form_validation->set_rules('file','App File','required');
        if ($this->form_validation->run())
        {
            $appname = $this->input->post('appname');
            $platform = $this->input->post('platform');
            $category1 = $this->input->post('category');
            $descripton = $this->input->post('description');
            $category = implode(",", $category1);
            echo "l";
            $data1=$this->appFileupload();
            echo "Break";
            $data2=$this->appImageupload();
            die;
            foreach ($data1 as $dataArray)
            {
                $fileName=$dataArray['file_name'];
            }
            foreach ($data2 as $dataArray)
            {
                $imageName=$dataArray['file_name'];
            }

            $data = array('name' => $appname, 'platform' => $platform, 'description' => $descripton, 'category' => $category,'file_name'=>$fileName,'image_name'=>$imageName,'dev_id'=>$dev_id);
                $this->Dev_model->addApp($data);

            //$this->appImageupload();
            echo "yolo";



        }
        else
        {
            $data['dataArray'] = $this->sessionStart();
            $category = $this->input->post('category');
            print_r($category);
            $this->load->view('dev/addApp', $data);
        }
    }

public function appFileupload()
{
    $config1['upload_path']          = './uploads/files';
    $config1['allowed_types']        = 'apk|exe';

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

    if ( ! $this->upload->appFileUpload('file'))
    {
        $error = array('error' => $this->upload->display_errors());
        print_r($error);

    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

        return $data;

    }
}

public function appImageupload()
{
    $config2['upload_path']          = './uploads/appImages';
    $config2['allowed_types']        = 'gif|jpg|png';
    $config2['max_size']             = 1000000000;
    $config2['max_width']            = 10240000;
    $config2['max_height']           = 76800000;

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

    if ( ! $this->upload->appImageUpload('app_pic'))
    {
        $error = array('error' => $this->upload->display_errors());
        print_r($error);

    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
        return $data;

    }
}

输出如下:

lBreak
Array ( [error] =>
    The filetype you are attempting to upload is not allowed.
)

所以,如果我交换appFileupload()appImageupload()的位置,那么它将为'apk | exe'文件提供相同的错误,现在它正在为appImageupload()提供错误。如果你问我怎么知道这个?然后答案是,我已经检查了他们的文件夹,一个上传而不是另一个。

CodeIgniter版本是:3.x

2 个答案:

答案 0 :(得分:0)

添加*代替另一种类型。

 $config['allowed_types'] = '*';

我只是建议将其用于测试目的

编辑:

我不确定,但这会有所帮助。

您可以尝试查看system / libraries / Upload.php第199行:

$this->_file_mime_type($_FILES[$field]);

将该行更改为:

$this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();

答案 1 :(得分:0)

好吧哈哈,我正在回答我自己的问题。

首先,使用$ config2再次加载库将不起作用,因为库已经加载一次并且$ config1将保持加载状态。要加载新配置,请使用:

:!