Heim  >  Artikel  >  php教程  >  php 获取 multipart/form

php 获取 multipart/form

WBOY
WBOYOriginal
2016-06-06 19:54:031437Durchsuche

http://blog.csdn.net/gold2008/article/details/8496489 用php做一个转发程序,就是从浏览器收到什么数据,就完整的转发到另外一个url 进行处理, GET, POST 都正常,但是在上传图片的时候,确发现不能上传成功,查资料后了解到。 php://input ,$HTTP_RAW_

http://blog.csdn.net/gold2008/article/details/8496489


用php做一个转发程序,就是从浏览器收到什么数据,就完整的转发到另外一个url 进行处理, GET, POST 都正常,但是在上传图片的时候,确发现不能上传成功,查资料后了解到。

php://input  ,$HTTP_RAW_POST_DATA 不能用于 enctype="multipart/form-data"  因为 php会试图解析所收到的数据,能解析就放入 $_POST, $_GET 数组里,不能解析,才会放到 php://input  里。

根据这个思路,在apache部分,人为的把 Content-Type 从 multipart/form-data 改成其他的一个名字,这样php就不会解析POST的数据了。http://stackoverflow.com/questions/1361673/get-raw-post-data  这个人分享了他的实现方法。

apache 下,在 .htaccess 文件里加入:

SetEnvIf Content-Type ^(multipart/form-data)(.*) MULTIPART_CTYPE=$1$2
RequestHeader set Content-Type application/x-httpd-php env=MULTIPART_CTYPE

然后在php程序里,通过 file_get_contents('php://input'); 可以得到原始数据。 然后重组下数据,就可以发送出去了。


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn