• <bdo id='nezI0'></bdo><ul id='nezI0'></ul>

  • <i id='nezI0'><tr id='nezI0'><dt id='nezI0'><q id='nezI0'><span id='nezI0'><b id='nezI0'><form id='nezI0'><ins id='nezI0'></ins><ul id='nezI0'></ul><sub id='nezI0'></sub></form><legend id='nezI0'></legend><bdo id='nezI0'><pre id='nezI0'><center id='nezI0'></center></pre></bdo></b><th id='nezI0'></th></span></q></dt></tr></i><div id='nezI0'><tfoot id='nezI0'></tfoot><dl id='nezI0'><fieldset id='nezI0'></fieldset></dl></div>
    <tfoot id='nezI0'></tfoot>

      <legend id='nezI0'><style id='nezI0'><dir id='nezI0'><q id='nezI0'></q></dir></style></legend>

        <small id='nezI0'></small><noframes id='nezI0'>

      1. 如何优雅地处理超过 PHP `post_max_size` 的文件?

        How to gracefully handle files that exceed PHP#39;s `post_max_size`?(如何优雅地处理超过 PHP `post_max_size` 的文件?)

              <tbody id='S0TSs'></tbody>

              <legend id='S0TSs'><style id='S0TSs'><dir id='S0TSs'><q id='S0TSs'></q></dir></style></legend>

            1. <tfoot id='S0TSs'></tfoot>
            2. <i id='S0TSs'><tr id='S0TSs'><dt id='S0TSs'><q id='S0TSs'><span id='S0TSs'><b id='S0TSs'><form id='S0TSs'><ins id='S0TSs'></ins><ul id='S0TSs'></ul><sub id='S0TSs'></sub></form><legend id='S0TSs'></legend><bdo id='S0TSs'><pre id='S0TSs'><center id='S0TSs'></center></pre></bdo></b><th id='S0TSs'></th></span></q></dt></tr></i><div id='S0TSs'><tfoot id='S0TSs'></tfoot><dl id='S0TSs'><fieldset id='S0TSs'></fieldset></dl></div>
                  <bdo id='S0TSs'></bdo><ul id='S0TSs'></ul>

                  <small id='S0TSs'></small><noframes id='S0TSs'>

                  本文介绍了如何优雅地处理超过 PHP `post_max_size` 的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个将文件附加到电子邮件的 PHP 表单,并尝试优雅地处理上传文件太大的情况.

                  I'm working on a PHP form that attaches a file to an email, and trying to gracefully handle cases where the uploaded file is too large.

                  我了解到 php.ini 中有两个设置会影响文件上传的最大大小:upload_max_filesizepost_max_size.

                  I've learned that there are two settings in php.ini that affect the maxiumum size of a file upload: upload_max_filesize and post_max_size.

                  如果文件大小超过upload_max_filesize,PHP 将文件大小返回为0.没关系;我可以检查一下.

                  If a file's size exceeds upload_max_filesize, PHP returns the file's size as 0. That's fine; I can check for that.

                  但如果它超过 post_max_size,我的脚本会静默失败并返回空白表单.

                  But if it exceeds post_max_size, my script fails silently and goes back to the blank form.

                  有什么办法可以捕捉到这个错误?

                  推荐答案

                  来自 文档 :

                  如果发布数据的大小更大比 post_max_size、$_POST 和$_FILES 超全局变量为空.这可以通过各种方式进行跟踪,例如通过将 $_GET 变量传递给处理数据的脚本,即 <formaction="edit.php?processed=1">,和然后检查 $_GET['processed'] 是否设置.

                  If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.

                  不幸的是,PHP 似乎没有发送错误.而且由于它发送的是空的 $_POST 数组,这就是您的脚本返回空白表单的原因 - 它认为它不是 POST.(相当糟糕的设计决策恕我直言)

                  So unfortunately, it doesn't look like PHP sends an error. And since it sends am empty $_POST array, that is why your script is going back to the blank form - it doesn't think it is a POST. (Quite a poor design decision IMHO)

                  这个评论者也有一个有趣的想法.

                  似乎更优雅的方式是post_max_size 和之间的比较$_SERVER['CONTENT_LENGTH'].请请注意,后者不仅包括上传文件的大小加上发布数据还有多部分序列.

                  It seems that a more elegant way is comparison between post_max_size and $_SERVER['CONTENT_LENGTH']. Please note that the latter includes not only size of uploaded file plus post data but also multipart sequences.

                  这篇关于如何优雅地处理超过 PHP `post_max_size` 的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

                  <small id='uI0gp'></small><noframes id='uI0gp'>

                  <legend id='uI0gp'><style id='uI0gp'><dir id='uI0gp'><q id='uI0gp'></q></dir></style></legend>

                          <bdo id='uI0gp'></bdo><ul id='uI0gp'></ul>
                          <i id='uI0gp'><tr id='uI0gp'><dt id='uI0gp'><q id='uI0gp'><span id='uI0gp'><b id='uI0gp'><form id='uI0gp'><ins id='uI0gp'></ins><ul id='uI0gp'></ul><sub id='uI0gp'></sub></form><legend id='uI0gp'></legend><bdo id='uI0gp'><pre id='uI0gp'><center id='uI0gp'></center></pre></bdo></b><th id='uI0gp'></th></span></q></dt></tr></i><div id='uI0gp'><tfoot id='uI0gp'></tfoot><dl id='uI0gp'><fieldset id='uI0gp'></fieldset></dl></div>

                              <tbody id='uI0gp'></tbody>
                          1. <tfoot id='uI0gp'></tfoot>