[英]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.