在这里,我使用AFNetworking通过PHP将图像上传到服务器,但图像没有上传,我得到的回复是成功的,任何人都建议我上传图片时有任何问题
ios_code:
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代码:
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);
}
请帮我找到问题所在。谢谢你的帮助。