0

Here I use the AFNetworking to upload the image to the server by using the PHP, but the image is not uploaded, i getting the response as success, any one suggest me is there any problem in uploading the image

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 Code:

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);
    }

Please help me to find the problem. thanks for helping.

dineshprasanna
  • 1,284
  • 4
  • 20
  • 37
  • Look [this](http://stackoverflow.com/a/2326432/887325) – Bimawa Oct 08 '14 at 05:19
  • Any info in the server logs? Are you seeing the request arrive at all? - is your PHP API being called? – Woodstock Oct 08 '14 at 07:01
  • @Bimawa my ios coding is working well, i checked by passing the other webservice, My suggestion is may be php code is wrong. but i am not sure. please confirm me. – dineshprasanna Oct 08 '14 at 11:58
  • @dineshprasanna i don't know, need more info. [try this info](http://php.net/manual/en/features.file-upload.php) – Bimawa Oct 09 '14 at 04:22

0 Answers0