0

我正在通过 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 中接收图像,以便我可以保存它,或者是否有其他解决方案?请帮忙

4

1 回答 1

1

Mknetwork 正在通过 post 以十六进制格式发送图像,因此您需要从 post 接收图像并将其写入以下格式的新文件中

$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);
于 2015-04-23T08:41:25.917 回答