簡體   English   中英

從IOS MKNetwork接收圖像到PHP服務器

[英]Recieve image from IOS mknetwork to php server

我正在通過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"];

從PHP方面

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

$ _FILES顯示空白圖片,$ _ POST顯示以下響應

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

我希望在$ _FILES中接收圖像,以便我可以保存它,或者是否有其他解決方案? 請幫忙

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM