title: AFNetworking upload image
body: <p>I'm trying to upload an image to my server from my iOS app, but the "Unsuccessful" in the php script keep tricking. What am i doing wrong?</p>
  
  <p>The <code>Log</code> returns "<code>File = Unsuccessful</code>" and then then the binary file numbers.</p>
  
  <p>iOS (Upload image):</p>
  
  <pre><code>-(IBAction)uploadPhoto:(id)sender{
  
      AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://SERVERURL"]];
      manager.responseSerializer = [AFHTTPResponseSerializer serializer];
      NSData *imageData = UIImageJPEGRepresentation(pickedImage, 0.5);
      NSDictionary *parameters = @{@"message": self.descriptionView.text};
      AFHTTPRequestOperation *op = [manager POST:@"rest.of.url" parameters:parameters constructingBodyWithBlock:^(id&lt;AFMultipartFormData&gt; formData) {
          //do not put image inside parameters dictionary as I did, but append it!
          [formData appendPartWithFileData:imageData name:@"file" fileName:@"upload.jpg" mimeType:@"image/jpeg"];
      } success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@ ***** %@", operation.responseString, error);
     }];
      [op start];
  
  
          [self dismissViewControllerAnimated:YES completion:nil];
      } 
  }
  </code></pre>
  
  <p>PHP CODE:</p>
  
  <pre><code>&lt;?
  if(!empty($_POST)) 
  {
      $message = $_POST['message'];
      $directory = $_SERVER['DOCUMENT_ROOT'] . '/pictures';
      $file = basename($_FILES['userfile']['upload.jpg']);
      $uploadfile = $directory . $file;
      var_dump($_FILES);
      $randomPhotoID = md5(rand() * time());
  echo 'file='.$file;
  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
         echo 'successful';
  
      }
      else
      {
      echo 'unsuccessful';
  
  }
  }
  else
  {
      echo('Empty post data');
  }
  ?&gt;
  </code></pre>