如何处理移动设备发送的图像? [英] How to handle images sent by a mobile device?
问题描述
手机开发人员正在发送这样的头文件:
Content-Disposition:form-data; NAME = photo_1; filename =photo_1.jpg
Content-Type:application / octet-stream
寻找发送的图像,这是正常的HTML表单相同的方法?我应该寻找$ _FILES吗?
或者,使用PHP,我将如何找到他的图片?
不显示它是通过一个表单发送,即< form enctype = multipart / form-data>
和< input type =file>
,所以 $ _ FILES
数组将不会被填充。 >
您可能需要阅读:
$ HTTP_RAW_POST_DATA
或do:
$ rawPost = file_get_contents(php:// input);
从 manual :
php:// input允许你从请求体中读取原始的
数据,如果是
的POST请求,它最好是
$ HTTP_RAW_POST_DATA,因为它不包含
取决于特殊的php.ini指令
此外,对于
$ HTTP_RAW_POST_DATA不是p在默认情况下使用
,这是一个潜在的更少的
内存密集型替代
激活
always_populate_raw_post_data。
php://输入不可用于
enctype =multipart / form-data。
欲了解更多信息,请查看:
http://php.net/manual/en/wrappers.php.php
http://php.net/manual/en/reserved.variables.httprawpostdata.php
A peer of mine is developing an iPhone application that will allow users to post images on my site via my API. I am building the part of the API that will accept and process the images.
The mobile developer is sending headers like such:
Content-Disposition: form-data; name="photo_1"; filename="photo_1.jpg"
Content-Type: application/octet-stream
When looking for the images sent, is it the same method as with normal HTML forms? Should I look for $_FILES?
Or, using PHP, how would I find his image?
Doesn't appear it's being sent via a form, i.e., <form enctype=multipart/form-data">
and <input type="file">
, so the $_FILES
array won't be populated.
You'll probably need to read:
$HTTP_RAW_POST_DATA
or do:
$rawPost = file_get_contents("php://input");
From the manual:
php://input allows you to read raw data from the request body. In case of POST requests, it preferrable to $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".
For more info, check out:
http://php.net/manual/en/wrappers.php.php
http://php.net/manual/en/reserved.variables.httprawpostdata.php
这篇关于如何处理移动设备发送的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!