title: multipar HTTP POST - objective-c
body: <p>I try to send a POST to my php page for upload a file and put it in a specific folder, this is the code I use on my osx app:</p>
  
  <pre><code>- (NSMutableURLRequest *) createRequest:(NSString *)string {
  
  NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:string];
  
  NSString *urlString = @"http://www.allmyapp.net/wp-content/uploadFile.php";
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  [request setURL:[NSURL URLWithString:urlString]];
  [request setHTTPMethod:@"POST"];
  
  NSString *boundary = @"---------------------------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 stringWithFormat:@"Content-Disposition: form-data; name='userfile'; filename='%@';\r\n",[string lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[NSData dataWithData:xmlData]];
  [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
  
  
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name='dest'\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[@"Test Path" dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
  
  
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  [request setHTTPBody:body];
  
  return request;
  </code></pre>
  
  <p>}</p>
  
  <p>and this is my php:</p>
  
  <pre><code>$uploaddir = 'test/';
  $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  
  echo('Dest:' . $_POST['dest'] . '     ');
  
  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
      echo "File is valid, and was successfully uploaded.\n";
  } else {
      echo "Possibile attacco tramite file upload!\n";
  }
  
  echo 'Alcune informazioni di debug:';
  print_r($_FILES);
  </code></pre>
  
  <p>The file is uploaded while I don't see <strong>$_POST['dest']</strong> where is the mistake?</p>