问题描述
这就是我正在处理的事情。我们的一个程序有一个用户用来请求支持的支持表单。这个表单的作用是对一个PHP脚本执行一个HTTP POST请求,该脚本应该收集信息并将其转发给支持的电子邮件地址。 POST请求包含三个 Content-Type:text / plain
的文本字段,可以使用 $ _ POST轻松读取<$ fieldname']
。然而,这个POST请求中的一些内容是类型为 Content-Type:application / octet-stream
的文件。使用 $ _ POST
似乎不适用于这些文件。如何阅读这些文件的内容?
预先感谢您。
$ $ p $内容= file_get_contents($ _ FILES ['myfile '] [' tmp_name的值']);
您可以找到更多信息。这只有在您的请求中使用 / form-data 编码时才有效。
您可以读取原始POST数据,然后解析它:
$ rawPost = file_get_contents('php:// input');
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 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?
Thank you in advance.
You have to use the $_FILES superglobal:
$contents = file_get_contents($_FILES['myfile']['tmp_name']);
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:
$rawPost = file_get_contents('php://input');
这篇关于如何接收使用“application / octet-stream”发送的POST数据在PHP中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!