title: Posting File with PHP/CURL to ASP.NET MVC 2 Controller
body: <p>sorry if this might be a cheesy question, but unfortunately I cannot change the project setup. 
  I have a form on a php page, which is supposed to post some text fields and a file input to a MVC Controller Action. The posting part works, and I successfully receive the text data in my ViewModel. However, I have no idea how tto receive the file (image, will be either jpg or png). The ID and NAME of the input type file is "UserIcon".</p>
  
  <p>In the ActionResult I tried it with HttpPostedFileBase like this:</p>
  
  <pre><code>public virtual ActionResult RegisterJson(RegistrationModels model, HttpPostedFileBase UserIcon)
  </code></pre>
  
  <p>But UserIcon is always NULL. Instead, if I have the file as part of the <code>RegistrationModels</code> Model:</p>
  
  <pre><code>    [DisplayName("Ihr Foto")]
      public string UserIcon { get; set; }   
  </code></pre>
  
  <p>I receive the curl path: <code>@C:\\Windows\\Temp\\phpA03D.tmp;filename=Penguins.jpg;</code> as string.</p>
  
  <p>But from here I have absolutely no clue as to what I have to do next to save the file. I tried to add to the curl header the <code>$header = array("Content-type: multipart/form-data");</code>
  but then all the posted form fields are NULL. </p>
  
  <p>I'd be so grateful if anyone could point me in the right direction! I think I'm having a main blackout here and doing something completely wrong :-S</p>
  
  <p>This is the curl code which posts to the MVC Action:</p>
  
  <pre><code>    $postargs = array();
      foreach ($_FILES as $param =&gt; $file) {
          $postargs[$param] = '@' . $file['tmp_name'] . ';filename=' . $file['name'] . ';';
      }
      $fields_string = "";
      //url-ify the data for the POST
      foreach($_POST as $key=&gt;$value) {
          $fields_string .= $key.'='.$value.'&amp;';
      }
  
      $fields_string .= http_build_query($postargs);
  
      $ch = curl_init();
  
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_POST,count($_POST));
      curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
  
      $result = curl_exec($ch);
  
      curl_close($ch);
  </code></pre>
  
  <p>Thanks alot!!</p>
  
  <p>Cheers,
  Caroline</p>