【问题标题】:Upload file and Internal Server Error only for one file, others are ok仅针对一个文件上传文件和内部服务器错误,其他文件都可以
【发布时间】:2019-12-03 09:20:44
【问题描述】:

我有一个奇怪的问题。 我有一个上传文件的表格。

一切正常...但今天上传后出现错误:

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

Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

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

经过一些测试,我发现问题只是我的一个文件!

此文件为 PDF。

我尝试重命名它。没有成功。 我尝试通过服务在线检查它是否是有效的 PDF……它是有效的。 文件没有损坏(我可以查看)

如果我将其压缩并上传,一切正常。 其他文件都可以上传....只有这个特定的文件会导致 500 错误!

我也插入了:

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

在 index.php 页面的开头...但我总是收到 500 错误...没有向我显示调试信息...

可能是什么问题?邪恶文件?

我的 index.php 是一个标准的上传脚本:

<?php

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

// if I UNCOMMENT THIS 2 LINES, STILL GET 500 ERROR...VERY STRANGE AT THIS POINT
//var_dump($_FILES);
//exit();


if ( isset($_POST['action']) && $_POST['action'] == "upload" ) {

    if ( isset($_FILES['file']) ) {

        $upload = upload_file($_FILES['file']); //<-- my custom function to save to disk

        if ( !$upload['Error'] ) {

            // do some stuff

        }

    }

    header("Location: ../");
    exit();

}

更新:一些信息。如果我在带有 WAMP 服务器的 localhost 上尝试它,一切正常。在线使用时出现错误

更新 2:这不是文件大小问题。问题只出现在一个特定的服务器上......在其他服务器上都可以:这是来自服务器的日志错误:ModSecurity: Access denied with code 44 (phase 2). Match of "eq 0" against "MULTIPART_UNMATCHED_BOUNDARY" required. [file "/etc/httpd/conf.d/mod_security.conf"] [line "34"] [id "200003"] [msg "Multipart parser detected a possible unmatched boundary."]

【问题讨论】:

  • 此文件的大小是否比您测试的其他文件大?如果是,您可以尝试上传另一个更大的文件吗?您可以访问 php 配置和服务器日志吗?
  • @MaxChernopolsky 嗨,Max,文件大小不是问题...我上传的文件比这个大。是的,这是日志错误:ModSecurity: Access denied with code 44 (phase 2)。需要匹配“eq 0”与“MULTIPART_UNMATCHED_BOUNDARY”。 [file "/etc/httpd/conf.d/mod_security.conf"] [line "34"] [id "200003"] [msg "Multipart parser检测到一个可能的不匹配边界。"]
  • 所以,mod_sequirity 阻止了它。考虑关闭 mod_security,否则,需要弄清楚并配置它。

标签: php file upload


【解决方案1】:

该特定服务器(ModSecurity)上传的最大大小是多少问题只出现在一个特定服务器中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 2015-10-11
    • 2018-03-18
    • 2013-12-10
    相关资源
    最近更新 更多