title: Image upload iphone to php server
body: <p>i am using following code to upload image to php sever but IOException message is displayed can anybody help me in this?</p>
  
  <pre><code>- (void)uploadFileToURL:(NSURL *)url FileData:(NSData *)fileData FileParameterName:(NSString *)fileParameterName FileName:(NSString *)fileName withParameters:(NSDictionary *)parameters
  {
      NSMutableString *params = nil;
      NSURL *finalURL = url;
      if (parameters != nil)
      {
          params = [[NSMutableString alloc] init];
          for (id key in parameters)
          {
              NSString *encodedKey = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
              CFStringRef value = (CFStringRef)[[parameters objectForKey:key] copy];
              // Escape even the "reserved" characters for URLs 
              // as defined in http://www.ietf.org/rfc/rfc2396.txt
              CFStringRef encodedValue = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 
                                                                                 value,
                                                                                 NULL, 
                                                                                 (CFStringRef)@";/?:@&amp;=+$,", 
                                                                                 kCFStringEncodingUTF8);
              [params appendFormat:@"%@=%@&amp;", encodedKey, encodedValue];
              CFRelease(value);
              CFRelease(encodedValue);
          }
          [params deleteCharactersInRange:NSMakeRange([params length] - 1, 1)];
              NSString *urlWithParams = [[url absoluteString] stringByAppendingFormat:@"?%@", params];
              finalURL = [NSURL URLWithString:urlWithParams];
          }
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:finalURL
                                                             cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                         timeoutInterval:60.0];
      NSString *boundary = @"---------------------------14737809831466499882746641449";
      NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
      [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
      NSMutableData *postbody = [NSMutableData data];
      [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
      [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
      [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
      [postbody appendData:[NSData dataWithData:fileData]];
      [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  
      [request setHTTPBody:postbody];
      [request setHTTPMethod:@"POST"];
      [self startConnection:request];
  }
  </code></pre>