【问题标题】:Recieve image from IOS mknetwork to php server从 IOS 网络接收图像到 php 服务器
【发布时间】:2014-08-11 07:59:08
【问题描述】:

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

【问题讨论】:

    标签: php ios image-uploading mknetworkengine


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-09
      • 2014-04-27
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多