简体   繁体   English

从IOS MKNetwork接收图像到PHP服务器

[英]Recieve image from IOS mknetwork to php server

I am sending image through MKnetwork to php server... on php side the image is recieved in $_POST instead of $_FILES... here is my code from ios side 我正在通过MKnetwork将图像发送到php服务器...在php端,图像以$ _POST而不是$ _FILES的形式接收...这是我来自ios端的代码

UIImage *image = [UIImage imageWithContentsOfFile:fullImgPath];// fullpath contains the path of image
NSData *imageData = UIImageJPEGRepresentation(image, 0.0);

MKNetworkEngine *engine=[[MKNetworkEngine alloc]initWithHostName:nil];

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:imageData forKey:@"uploadedfile"];
NSString *url=@"http://ilogiks.co.uk/demo/image/upload.php";
MKNetworkOperation *op=[engine operationWithURLString:url params:dict httpMethod:@"POST"];

From php side 从PHP方面

echo "POST";
var_dump($_POST);
echo "FILES";
var_dump($_FILES);

$_FILES show empty image and $_POST show following response $ _FILES显示空白图片,$ _ POST显示以下响应

array(1){
["uploadedfile"]=>
string(50523) "<ffd8ffe0 00104a46 49460001.............

I want image to be recieved in $_FILES so that i can save it or if there is an other solution possible? 我希望在$ _FILES中接收图像,以便我可以保存它,或者是否有其他解决方案? please help 请帮忙

Mknetwork is sending image in hex format through post so you need to receive it from post and write it in a new file in following format Mknetwork正在通过帖子以十六进制格式发送图像,因此您需要从帖子中接收图像并将其写入以下格式的新文件中

$img = $_POST['uploadedfile'];
$img = str_replace("<","",$img);
$img = str_replace(">","",$img);
$img = str_replace(" ","",$img);
$img = pack("H*", $img);
$file = "img.png";
$f = fopen($file,'wb');
fwrite($f, $img);
fclose($f);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从iPhone接收PHP服务器中的图像 - How to recieve image in a php server from an iphone 是否可以从PHP服务器接收来自Ajax的响应 - is it possible to recieve response from with Ajax from PHP server 将图像从iOS / Swift上传到PHP服务器 - Uploading an image from iOS/Swift to PHP server iOS:将图像上传到服务器Php从ios设备无法正常工作? - IOS:upload a image to server Php From ios devices is Not Working? 努力将图像从iOS上传到我的PHP服务器 - Struggling with image upload from my iOS to my PHP server 从iOS应用将多部分图片上传到PHP服务器 - Upload multipart image to PHP server from iOS app PHP服务器无法使用$ .http()。post请求从angularjs接收json变量 - php server unable to recieve the json variable from angularjs using $.http().post request 如何从其他服务器接收和存储图像文件,并通过参数与程序进行传递? - How to recieve & store an image file from another server, being passed programatically with paramaters? 从另一台服务器向&lt;&gt;发送和接收JSON,并以HTML格式(PHP脚本)呈现答案 - Send and recieve JSON to<>from another server and render answer in HTML ( PHP script ) 从PHP文件中获取变量使用fopen吗? - Recieve Variable From php file Using fopen?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM