1
 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.
)

所以,如果我交换 'apk|exe' 文件的位置,appFileupload()appImageupload()会给 'apk|exe' 文件提供相同的错误,而现在它给appImageupload(). 如果你问我怎么知道这件事?那么答案是,我检查了他们的文件夹,其中一个已上传,但另一个没有。

CodeIgniter 版本为:3.x

4

2 回答 2

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();
于 2017-10-16T09:17:35.433 回答
0

好吧,大声笑,我正在回答我自己的问题。

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

$this->upload->initialize($config2);
于 2017-10-16T17:40:43.700 回答