在PHP中接收多部分POST数据请求 [英] Receiving multipart POST data requests in PHP
问题描述
我想在 PHP中收到以下
HTTP
请求:
I want to receive the following HTTP
request in PHP:
Content-type: multipart/form-data;boundary=main_boundary
--main_boundary
Content-type: text/xml
<?xml version='1.0'?>
<content>
Some content goes here
</content>
--main_boundary
Content-type: multipart/mixed;boundary=sub_boundary
--sub_boundary
Content-type: application/octet-stream
File A contents
--sub_boundary
Content-type: application/octet-stream
File B contents
--sub_boundary
--main_boundary--
(注意:我缩进了子部分只是为了使这篇文章更具可读性。)
(Note: I have indented the sub-parts only to make it more readable for this post.)
我不是很流利的PHP,我想得到一些帮助/指针,以了解如何在PHP代码中接收这种多部分表单请求。我曾经写过一些代码,我收到了一个标准的HTML表单,然后我可以通过在 $ HTTP_GET_VARS
数组中使用它们的名称作为索引键来访问表单元素,但是在此case没有表单元素名称,表单数据部分不是线性的(即子部分=多级数组)。
I'm not very fluent in PHP and would like to get some help/pointers to figure out how to receive this kind of multipart form request in PHP code. I have once written some code where I received a standard HTML form and then I could access the form elements by using their name as index key in the $HTTP_GET_VARS
array, but in this case there are no form element names, and the form data parts are not linear (i.e. sub parts = multilevel array).
感谢任何帮助!
/ Robert
推荐答案
$ HTTP_GET_VARS
, $ HTTP_POST_VARS
等是一种过时的表示法,你应该使用 $ _ GET
, $ _ POST
等等。
$HTTP_GET_VARS
, $HTTP_POST_VARS
, etc. is an obsolete notation, you should be using $_GET
, $_POST
, etc.
现在,文件内容应该在 $ _ FILES
全局数组,而如果没有元素名称,我不确定其余内容是否会显示在 $ _ POST
中。无论如何,如果 php.ini 中的 always_populate_raw_post_data
设置为true,则数据应该在 $ HTTP_RAW_POST_DATA $ c $中C>。此外,在阅读 php:// input 时,应显示整个请求。
Now, the file contents should be in the $_FILES
global array, whereas, if there are no element names, I'm not sure about whether the rest of the content will show up in $_POST
. Anyway, if always_populate_raw_post_data
setting is true in php.ini, the data should be in $HTTP_RAW_POST_DATA
. Also, the whole request should show up when reading php://input.
这篇关于在PHP中接收多部分POST数据请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!