上传多张图片导致500错误

发布于 2024-10-25 18:37:16 字数 3264 浏览 4 评论 0原文

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

这是我的代码。

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 日志文件的内容:

[2011 年 3 月 23 日星期三 02:29:41] [错误] [客户端 129.21.129.32] ModSecurity:访问被拒绝,代码 500(第 4 阶段)。模式匹配“(?:\b(?:(?:s(?:elect list),因为它不包含在 (?:聚合函数并且没有|聚合函数或) GROUP BY 子句|提供的参数中不是有效的 (?:(?:M(?:S |y)|Postgre)SQL|O(?:racle|DBC)))|S(?:yntax error conversioni ..." at RESPONSE_BODY。[文件“/etc/apache2/conf.d/modsecurity/modsecurity_crs_50_outbound.conf”] [行“23”] [id“970003”] [msg“SQL信息泄漏”] [严重性“警告”] [标记“泄漏/错误” ] [主机名“hostname.com”] [uri“/longboard/index.php/board/add”] [unique_id “TYmTVYEVgWYAAASKoIcAAAAJ”]

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

I modified a script i found on here to do process multiple pictures being uploaded at once. However when I try to run the script it throws an error. I use to have the script only allow one picture upload at time and that worked fine without any issue.

Here is my code.

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;
}

Here is the 500 error.

Internal Server Error

The server encountered an internal
error or misconfiguration and was
unable to complete your request.

Please contact the server
administrator, webmaster@localhost and
inform them of the time the error
occurred, and anything you might have
done that may have caused the error.

More information about this error may
be available in the server error log.

Additionally, a 500 Internal Server
Error error was encountered while
trying to use an ErrorDocument to
handle the request.

This is what the apache log file says:

[Wed Mar 23 02:29:41 2011] [error] [client 129.21.129.32] ModSecurity: Access denied with code 500 (phase 4). Pattern match "(?:\b(?:(?:s(?:elect list because it is not contained in (?:an aggregate function and there is no|either an aggregate function or the) GROUP BY clause|upplied argument is not a valid (?:(?: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"]

Based on the error message I think modsecurity is blocking the script for some reason but i'm not sure why. Any insight would be greatly appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧街凉风 2024-11-01 18:37:16

尝试禁用 mod_security ,
在 .htaccess 添加这个

SecFilterEngine Off

try disabling mod_security ,
in .htaccess add this

SecFilterEngine Off
星星的轨迹 2024-11-01 18:37:16

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

It ended up being a database error. Mod_security was blocking the error message. I went into the mod_security log file and found which rule was causing it to throw the 500 error. I then went into the file with that rule and commented it out. I restarted apache and retested and then the database error showed. I'm thinking of leaving this rule commented out since this is a development server. (It does broadcast to the whole world though, and the reason I have Mod_security installed.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文