PHP:post 全局变量的总长度是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2276759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:50:11  来源:igfitidea点击:

PHP: whats the total length of a post global variable?

phppostglobal-variablesstring-length

提问by phpNutt

I was wondering if anybody knows the total length that a post global could be. e.g:

我想知道是否有人知道 post global 的总长度。例如:

$_POST['formInput'] = "hello world, how long can i be?";

I am creating a site where someone will enter an unknown amount of chars into a textarea, so potentially it could be 2 pages on a word document. So if anybody knows of any other methods of how i can do this apart from using a post global? (it cant be saved in a file, as its important data that i dont want other people to find) That would be very helpful.

我正在创建一个网站,有人将在其中输入未知数量的字符到 textarea 中,因此它可能是 word 文档上的 2 页。因此,如果有人知道除了使用 post global 之外我还可以如何做到这一点的任何其他方法?(它不能保存在文件中,因为它的重要数据我不想让其他人找到)这将非常有帮助。

Thanks

谢谢

回答by Sampson

Check your php.ini for post_max_size. This is typically about 8mb by default, but if you're on shared-hosting, it could definitely vary.

检查您的 php.ini 中的post_max_size. 默认情况下,这通常约为 8mb,但如果您使用的是共享主机,则肯定会有所不同。

; Maximum size of POST data that PHP will accept.
post_max_size = 8M

You'll have to use $_POSTif you wish to send large amounts of data to the server. For further study, I'd suggest checking out POST Method Uploadsin the documentation.

你将不得不使用$_POST,如果你想大量数据发送到服务器。为了进一步研究,我建议查看文档中的POST Method Uploads

回答by troelskn

$_POSTis populated from the body of a HTTP-request. Since there are no restrictions on the size of a HTTP-request, there are no restrictions in the protocol layer. However PHP has some limitations on how much input it will read. You can control this with the ini-setting post_max_size

$_POST从 HTTP 请求的正文填充。由于对 HTTP 请求的大小没有限制,因此协议层没有限制。但是,PHP 对读取的输入量有一些限制。您可以使用 ini 设置来控制它post_max_size

回答by Petr Novotny

Another problem can be the default limit in php.ini for directive max_input_vars (default 1000), not only the post_max_size. If you have e.g. a very large form with thousands of checkboxes the $_POST array will have only 1000 keys.

另一个问题可能是 php.ini 中指令 max_input_vars(默认 1000)的默认限制,而不仅仅是 post_max_size。例如,如果您有一个包含数千个复选框的非常大的表单,则 $_POST 数组将只有 1000 个键。

回答by Pascal MARTIN

If you want some large amount of data sent from the browser to the server, you'll have to use HTTP POST method -- which means the data will be received, on the PHP side, in the $_POSTsuperglobal array ; there's not much you can do about that.

如果您想将大量数据从浏览器发送到服务器,则必须使用 HTTP POST 方法——这意味着数据将在 PHP 端的$_POST超全局数组中接收;对此你无能为力。

The configuration directive post_max_sizedefines the maximum amount of data that can be received using the POST method -- you might need to set that to a value higher than the default one, depending on your needs.

配置指令post_max_size定义了可以使用 POST 方法接收的最大数据量——您可能需要将其设置为高于默认值的值,具体取决于您的需要。

And, as said on the documentation of post_max_size, the value set for memory_limitcan also have its importance.

而且,正如在 的文档中所说post_max_size,为 设置的值memory_limit也很重要。