简体   繁体   中英

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

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

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

$_FILES show empty image and $_POST show following response

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? 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

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM