Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can upload image from iOS App to <code>PHP server</code> like this two way:</p> <p><strong>Using <a href="http://afnetworking.com/" rel="noreferrer">New AFNetworking</a> :</strong></p> <pre><code>#import "AFHTTPRequestOperation.h" #import "AFHTTPRequestOperationManager.h" NSString *stringUrl =@"http://www.myserverurl.com/file/uloaddetails.php?" NSString *string =@"http://myimageurkstrn.com/img/myimage.png" NSURL *filePath = [NSURL fileURLWithPath:string]; NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:userid,@"id",String_FullName,@"fname",String_Email,@"emailid",String_City,@"city",String_Country,@"country",String_City,@"state",String_TextView,@"bio", nil]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:stringUrl parameters:parameters constructingBodyWithBlock:^(id&lt;AFMultipartFormData&gt; formData) { [formData appendPartWithFileURL:filePath name:@"userfile" error:nil];//here userfile is a paramiter for your image } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"%@",[responseObject valueForKey:@"Root"]); Alert_Success_fail = [[UIAlertView alloc] initWithTitle:@"myappname" message:string delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; [Alert_Success_fail show]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { Alert_Success_fail = [[UIAlertView alloc] initWithTitle:@"myappname" message:[error localizedDescription] delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; [Alert_Success_fail show]; }]; </code></pre> <p><strong>Second use NSURLConnection:</strong></p> <pre><code>-(void)uploadImage { NSData *imageData = UIImagePNGRepresentation(yourImage); NSString *urlString = [ NSString stringWithFormat:@"http://yourUploadImageURl.php?intid=%@",1]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n", 1]] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:imageData]]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPBody:body]; [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; } </code></pre> <p>This both way working fine for uploading image from app to php server hope this helps for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload