如何接收使用“application / octet-stream”发送的POST数据在PHP中? [英] How to recieve POST data sent using "application/octet-stream" in PHP?
问题描述
POST请求包含三个 Content-Type:text / plain
的文本字段,可以使用 $ _ POST轻松读取<$ fieldname']
。然而,这个POST请求中的一些内容是类型为 Content-Type:application / octet-stream
的文件。使用 $ _ POST
似乎不适用于这些文件。如何阅读这些文件的内容?
预先感谢您。
$ $ p $内容= file_get_contents($ _ FILES ['myfile '] [' tmp_name的值']);
您可以找到更多信息手册中。这只有在您的请求中使用 您可以读取原始POST数据,然后解析它: Here's what I'm dealing with. One of our programs has a support form that users use to request support. What this form does is, it performs an HTTP POST request to a PHP script that's supposed to collect the info and forward it to the support e-mail address. The POST request contains three text fields of the type Thank you in advance. You have to use the $_FILES superglobal: You can find more information in the manual. This will only work if you are using multipart/form-data encoding in your request. You can otherwise read the raw POST data, then parse it yourself:
这篇关于如何接收使用“application / octet-stream”发送的POST数据在PHP中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ rawPost = file_get_contents('php:// input');
Content-Type: text/plain
which can be easily read in PHP using $_POST['fieldname']
. Some of the content in this POST request, however, are files, of type Content-Type: application/octet-stream
. Using $_POST
doesn't seem to work with these files. How do I go about reading the contents of these files?$contents = file_get_contents($_FILES['myfile']['tmp_name']);
$rawPost = file_get_contents('php://input');