使用codeigniter中的图像头进行图像验证以防止黑客攻击

时间:2016-09-10 12:06:09

标签: php forms codeigniter validation

我想要一种验证图像文件的方法。

我尝试使用图片类型及其格式和大小进行验证。我需要高精度的另一种验证。

我问,因为我的网站被包含代码的上传图片文件攻击了。黑客用.png格式编写代码并将其作为图像上传到我的网站。从那一刻起,他开始攻击我的网站。

请帮助我使用标题对图像文件进行高度验证。

我的验证如下:

 function upload()
    {
        //set preferences
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'txt|pdf';
        $config['max_size']    = '100';

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

        if (!$this->upload->do_upload('filename'))
        {
            // case - failure
            $upload_error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_file_view', $upload_error);
        }
        else
        {
            // case - success
            $upload_data = $this->upload->data();
            $data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' . $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
            $this->load->view('upload_file_view', $data);
        }
    }

1 个答案:

答案 0 :(得分:0)

您已经允许txt和pdf的文件类型。你应该使用

$config['allowed_types'] = 'gif|jpg|png';

如果是您要上传的图片。