上传多张图片导致500错误

时间:2011-03-23 06:37:03

标签: php codeigniter file-upload mod-security

我修改了我在这里找到的脚本来处理一次上传的多张图片。但是当我尝试运行脚本时会抛出错误。我用这个脚本只允许一次上传一张图片,而且没有任何问题。

这是我的代码。

Function uploadMultiple(){
    $config = array(
        'allowed_types' => 'jpg|png|jpeg|gif',
        'upload_path' => $this->board_path,
        'overwrite' => false,
        //'file_name' => $fileName

    );
    //print_r($config);

    $this->load->library('upload');
    $errorCount = 0;
    $results = array(
        'errorsPresent' => false,
    );
    $successCount = 0;

    //for each image...try to upload.  if it fails, add it to the error list.
    //keep a list of successful uploads.
    print_r($_FILES);
    for ($i = 0; $i<count($_FILES); $i++){
        echo 'here';
        $_FILES['userfile']['name']    = $_FILES['userfile' . $i]['name'];
        $_FILES['userfile']['type']    = $_FILES['userfile' . $i]['type'];
        $_FILES['userfile']['tmp_name'] = $_FILES['userfile' . $i]['tmp_name'];
        $_FILES['userfile']['error']       = $_FILES['userfile' . $i]['error'];
        $_FILES['userfile']['size']    = $_FILES['userfile' . $i]['size'];

        $config['file_name']     = 'img_' . time() . '.png'; //inserts the unix time into the file name.
        $config['upload_path']   = $this->board_path;
        $config['allowed_types'] = 'jpg|jpeg|gif|png';
        $config['max_size']      = '0';
        $config['overwrite']     = FALSE;
        $this->upload->initialize($config);

        if ( ! $this->upload->do_upload()){
            $results['errorsPresent'] = true;
            $results['error'][$errorCount] = $this->upload->display_errors();
            $errorCount ++;

        } else {
            $data = array('upload_data' => $this->upload->data());              
            $pictureData = $this->upload->data();
            $file_location = $pictureData['full_path'];
            $file_location = substr($file_location, 18);//this should probably be dynamic...
            $file_location = $this->db->escape($file_location);
            $results['success'][$successCount] = $file_location;

            chmod($pictureData['full_path'], 777); //don't need to give it execute permissions but oh well.
            $successCount ++;       
        }

    }

    return $results;
}

这是500错误。

  

内部服务器错误

     

服务器遇到内部问题   错误或错误配置,是   无法完成您的请求。

     

请与服务器联系   管理员,网站管理员@ localhost和   告诉他们错误的时间   发生了,你可能有任何东西   完成可能导致错误。

     

有关此错误的详细信息可能有效   在服务器错误日志中可用。

     

此外,500内部服务器   遇到错误错误   试图使用ErrorDocument   处理请求。

这是apache日志文件所说的内容:

  

[Wed Mar 23 02:29:41 2011] [错误] [client 129.21.129.32] ModSecurity:拒绝访问代码500(阶段4)。模式匹配“(?:\ b(?:(?:s(?:选择列表,因为它不包含在(?:一个聚合函数,并且没有|聚合函数或者)聚合函数或者> GROUP BY子句| upplied参数不是有效的(?:(?:M(?:S | y)| Postgre)SQL | O(?:racle | DBC)))| S(?:yntax error converti ...“at RESPONSE_BODY。[file “/etc/apache2/conf.d/modsecurity/modsecurity_crs_50_outbound.conf”] [line“23”] [id“970003”] [msg“SQL Information Leakage”] [severity“WARNING”] [tag“LEAKAGE / ERRORS” ] [hostname“hostname.com”] [uri“/longboard/index.php/board/add”] [unique_id“TYmTVYEVgWYAAASKoIcAAAAJ”]

根据错误消息,我认为modsecurity出于某种原因阻止了脚本,但我不确定原因。任何见解将不胜感激。

由于

2 个答案:

答案 0 :(得分:0)

尝试禁用mod_security, 在.htaccess中添加此

SecFilterEngine Off

答案 1 :(得分:0)

最终导致数据库错误。 Mod_security阻止了错误消息。我进入mod_security日志文件,发现哪个规则导致它抛出500错误。然后我按照该规则进入文件并对其进行了评论。我重新启动了apache并重新测试,然后显示数据库错误。我正在考虑将此规则注释掉,因为这是一个开发服务器。 (它确实向全世界广播,并且我安装了Mod_security的原因。)

相关问题