IOS端代码:
NSData?*data?=?UIImageJPEGRepresentation(image,?0.8);
NSString?*url?=?[SERVER_URL?stringByAppendingPathComponent:@”App/upload_img”];
NSMutableDictionary?*params?=?[[NSMutableDictionary?alloc]initWithCapacity:2];
params[@”byte”]?=?data;
[BNNetTools?post:url?params:params?success:^(id?json)?{
}?failure:^(NSError?*error)?{
}];
NSString?*url?=?[SERVER_URL?stringByAppendingPathComponent:@”App/upload_img”];
NSMutableDictionary?*params?=?[[NSMutableDictionary?alloc]initWithCapacity:2];
params[@”byte”]?=?data;
[BNNetTools?post:url?params:params?success:^(id?json)?{
}?failure:^(NSError?*error)?{
}];
PHP端代码:
$byte = $this->input->post(‘byte’);//接受上传数据流
$byte = str_replace(‘ ‘,”,$byte); //处理数据
$byte = str_ireplace(“<“,”,$byte);
$byte = str_ireplace(“>”,”,$byte);
$byte=pack(“H*”,$byte); //16进制转换成二进制
$path=’XXX/XXX/XXX/’;
file_put_contents($path,$byte);//以写文件的形式 写入对应目录
以上代码经测试有效,请各位使用者根据自己的实际情况,进行修改。如有任何意见,请在评论中进行回复,谢谢
4 thoughts on “IOS 客户端 上传图片 PHP 服务器端 接受”
Comments are closed.
欢迎
Happy New Year To You
看看!
Happy New Year.