i want to upload an image on to server my image view image for that i write a code like as
UIImage *image = self.uploadImageView.image;
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://199.16.128.49/~gzfknsfg/webservices/insert_image.php?foldername=comm_image&img_name=iosimage.jpeg" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:imageData name:@"name"];
} success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"Success: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@", error);
}];
then i got result success from above code but image not uploading in to server.
And my php
side code like as
if(isset($_REQUEST['foldername']) && isset($_REQUEST['img_name']))
{
$foldername=$_REQUEST["foldername"];
$img_name=$_FILES["img_name"]["name"];
$tmp=$_FILES["img_name"]["tmp_name"];
$targetfile="$foldername/".$img_name;
move_uploaded_file($tmp,$targetfile);
$json_result= array("status"=>"success" , "data"=>"file uploaded");
}
Thanks.
change the following line
[formData appendPartWithFormData:imageData name:@"name"];
to
[formData appendPartWithFileData:imageData name:@"img_name" fileName:@"iosimage.jpg" mimeType:@"image/jpeg"];
and it should work. :)