从ios到php的图像上传
在这里,我使用AFNetworking通过PHP将图像上传到服务器,但是图像没有上传,我得到的响应是成功的,有人建议我上传图像有问题吗 ios_代码:从ios到php的图像上传,php,ios,objective-c,afnetworking,Php,Ios,Objective C,Afnetworking,在这里,我使用AFNetworking通过PHP将图像上传到服务器,但是图像没有上传,我得到的响应是成功的,有人建议我上传图像有问题吗 ios_代码: AFHTTPClient *mutableReqClient = [[AFHTTPClient alloc] init]; NSMutableURLRequest *reqBody = [mutableReqClient multipartFormRequestWithMethod:@"POST" path:Siteurl parame
AFHTTPClient *mutableReqClient = [[AFHTTPClient alloc] init];
NSMutableURLRequest *reqBody = [mutableReqClient multipartFormRequestWithMethod:@"POST" path:Siteurl parameters:_params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSData *imData = UIImageJPEGRepresentation(imageToPost, 1);
[formData appendPartWithFileData:imData name:@"image"
fileName:@"image_name.jpeg"
mimeType:@"image/jpeg"];
}];
AFHTTPRequestOperation *saveAPI = [[AFHTTPRequestOperation alloc] initWithRequest:reqBody];
[saveAPI setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError* error;
NSMutableDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseObject //1
options:kNilOptions
error:&error];
NSLog(@"json :%@",json);
completed(json);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"JSON error%@",error);
}];
[saveAPI start];
请帮我找出问题所在。感谢您的帮助。在服务器日志中查找任何信息?你看到请求到达了吗你的PHP API被调用了吗?@Bimawa我的ios代码运行得很好,我通过另一个Web服务进行了检查,我的建议是可能PHP代码是错误的。但我不确定。请确认我。@dineshprasanna我不知道,需要更多信息。
public function saveImage($image, $image_name) {
$buffer = base64_decode($image);
//$source = imagecreatefromstring($buffer);
//$imageSave = imagejpeg($source, "upload/" . $image_name, 100);
//$imageSave = file_put_contents('../upload/'.$image_name,imagejpeg($source));
//imagedestroy($imageSave);
$file = fopen("upload/".$image_name, "wb");
fwrite($file, $buffer);
fclose($file);
}