【问题标题】:Error 500 while uploading images to the server将图像上传到服务器时出现错误 500
【发布时间】:2018-05-03 19:06:29
【问题描述】:

我用 PHP 构建了一个 CMS,它具有图库功能,您可以在其中选择多个图像并将其上传到服务器。对于图像的上传,我使用了一个名为 File-up,https://shabuninil.github.io/fileup/ 的插件,它可以让您使用 ajax-requests 将文件上传到服务器。 When multiple images are selected this plugin sends 1 (one) image per request, so if you select 5 images the plugin will send 5 ajax-requests to the server.在服务器上,有一个脚本获取插件发送的图像,它验证图像并使用 move_uploaded_file 函数将其移动到特定文件夹。问题是我以某种方式收到插件的某些请求的 500 错误。我尝试了关于此处发布的 500 错误的不同帖子,stackoverflow.com,以解决该问题,但没有成功。我想可能是服务器一次从插件收到了太多请求,所以我用 5 秒实现了 Jquery 的 setTimeout() 函数,但仍然没有成功。

我什至认为 CMS 可能有一些错误或其他问题,所以我通过将 CMS 放置在 co.nf 的另一台服务器上来测试 CMS,但在该服务器上我没有收到任何错误,一切正常,所以如果我米是正确的问题是在原始服务器上。我没有想法,所以,有人可以帮助我吗?提前致谢!

将图像放入特定文件夹的函数,在本例中为“上传”文件夹:

// Be sure we're dealing with an upload
if (is_uploaded_file($_FILES['filedata']['tmp_name']) === false) {
    throw new \Exception('Error on upload: invalid file definition');
}

// Rename uploaded file
$uploadName = $_FILES['filedata']['name'];
$ext        = strtolower(substr($uploadName, strripos($uploadName, '.') + 1));
$filename   = round(microtime(true)) . mt_rand() . '.' . $ext;
$target_dir = "../uploads/" . $filename;

if (move_uploaded_file($_FILES['filedata']['tmp_name'], $target_dir)) {
// Save filename into db
}

Image of the ajax-requests and their errors:

服务器错误文件中的错误:

[Mon Nov 20 01:17:44 2017] [error] [client IP_ADDRESS ] [client IP_ADDRESS] 
ModSecurity: Warning. Match of "eq 0" against "MULTIPART_UNMATCHED_BOUNDARY" 
required. [file "/services/mod_security-rules/00_asl_zz_strict.conf"] [line 
"37"] [id "330792"] [rev "2"] [msg "Multipart parser detected a possible 
unmatched boundary. This may be an impedence mismatch attack, a broken 
application or a broken connection.  This is not a false positive.  Check 
your application or client for errors."] [severity "NOTICE"] [tag "no_ar"]  
[hostname "MY_HOST"] [uri "/MY_SITE/cms/pages/upload.php"]

【问题讨论】:

  • 在使用 Safari 时不会发生这种情况吧?我问是因为 safari 存在问题(就像现在永远一样,愚蠢的苹果),其中 Connection: close 不会发生,它会在中途关闭下一个连接,从而切断提交数据。
  • 我没有在 safari 上测试过。我在 chrome 和 Opera 上测试了它
  • 好吧好吧!好吧,有些东西导致数据被截断:( 查明它可能很麻烦。我只遇到过那个 safari 浏览器的这个问题......当你得到一个不准确的重复错误时,它会令人沮丧!跨度>
  • 我明白了,谢谢 :)

标签: php jquery ajax server


【解决方案1】:

您遇到了一个 mod 安全错误,这让我怀疑您的服务器正在限制上传的大小。

default limit is 512kb,它很容易比现代图像文件小得多。

您可以使用以下命令将其增加到更高的限制,例如 1gb:

SecResponseBodyLimit 1048576

然后,您需要重新启动服务器以获取更改。

【讨论】:

  • 在哪里可以更改此属性?
  • 这取决于您的服务器配置。它们不应该在 httpd.conf 中,但它们可能是因为这是一个方便的地方来包含它们。你可以从那里开始,至少它们应该在那里被导入/需要。或者可以尝试通过您的服务器配置文件对其进行 grepping。
猜你喜欢
  • 2018-04-07
  • 2017-01-16
  • 1970-01-01
  • 1970-01-01
  • 2013-07-06
  • 2013-07-06
  • 1970-01-01
  • 2011-07-14
  • 1970-01-01
相关资源
最近更新 更多