如何接收使用“application / octet-stream”发送的POST数据在PHP中? [英] How to recieve POST data sent using "application/octet-stream" in PHP?

查看:7299
本文介绍了如何接收使用“application / octet-stream”发送的POST数据在PHP中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我正在处理的事情。我们的一个程序有一个用户用来请求支持的支持表单。这个表单的作用是对一个PHP脚本执行一个HTTP POST请求,该脚本应该收集信息并将其转发给支持的电子邮件地址。



POST请求包含三个 Content-Type:text / plain 的文本字段,可以使用 $ _ POST轻松读取<$ fieldname'] 。然而,这个POST请求中的一些内容是类型为 Content-Type:application / octet-stream 的文件。使用 $ _ POST 似乎不适用于这些文件。如何阅读这些文件的内容?

预先感谢您。

解决方案

你必须使用$ _FILES超全局:

$ $ 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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆