title: PHP Curl post with file attachment; custom content-type header
body: <p>I have to post a file to a server along side with a few post params. The documentation I received from this server admin shows an example of what the post request is supposed to look like (<em>*</em> NOTE the custom content type for the POST "multipart/x-api-remote-integration"):</p>
  
  <pre><code>POST /gateway/remote_send HTTP/1.0
  
  Content-Type: multipart/x-api-remote-integration; boundary=ABC1234
  
  Content-Length: 323
  
  --ABC1234
  
  Content-Type: application/x-www-form-urlencoded
  
  profile_name=username&amp;profile_pw=password1234&amp;attached_type=action_1
  
  --ABC1234
  
  Content-Type: text/csv
  
  Content-Disposition: attachment; filename="attachment.csv"
  row1
  row2
  row3
  
  --ABC1234--
  </code></pre>
  
  <p>Below is the php code:</p>
  
  <pre><code>&lt;?php
  function post(){
      $base_api_url = "https://hostserver.com/gateway/remote_send";
  
      $filename = realpath("/home/username/tests/test1234qwerty.csv");
  
      $payload['profile_name'] = "username";
      $payload['profile_pw'] = 'password1234';
      $payload['attached_type'] = 'action_1';
      $payload['filename'] = "@" . $filename . ";type=text/csv;";
  
      $curl_options = array(
          CURLOPT_URL =&gt; $base_api_url,
          CURLOPT_POST =&gt; true,
          CURLOPT_POSTFIELDS =&gt; http_build_query( $payload ),
          CURLOPT_HTTP_VERSION  =&gt; 1.0,
          CURLOPT_RETURNTRANSFER =&gt; true,
          CURLOPT_VERBOSE =&gt; true,
          CURLOPT_HEADER =&gt; false,
      );
  
      $curl = curl_init();
      curl_setopt_array( $curl, $curl_options );
      $result = curl_exec( $curl );
      curl_close ($curl);
      echo $result;
    }
  
  post();
  </code></pre>
  
  <p>From what I am receiving back from the server, it seems that the post fields are being received properly. However it's the file that is not being received. I'm not sure what I did wrong. Any input is greatly appreciated.</p>
  
  <p>EDIT: Attaching Verbose response:</p>
  
  <pre><code>* About to connect() to hostserver.com port 443 (#0)
  *   Trying x.x.x.x... * connected
  * successfully set certificate verify locations:
  *   CAfile: none
    CApath: /etc/ssl/certs
  * SSL connection using DHE-RSA-AES256-SHA
  *   ******** REDACTED ************
  *   SSL certificate verify ok.
  &gt; POST /gateway/remote_send HTTP/1.0
  Host: hostserver.com
  Accept: */*
  Content-Length: 110
  Content-Type: application/x-api-remote-integration
  
  * upload completely sent off: 110out of 110 bytes
  &lt; HTTP/1.1 200 OK
  &lt; Date: Mon, 19 Aug 2013 16:00:38 GMT
  &lt; Server: Apache/2.2.15 (Red Hat)
  &lt; Pragma: no-cache
  &lt; CacheControl: no-cache
  &lt; Cache-Control: no-cache
  &lt; Expires: -1
  &lt; Connection: close
  &lt; Content-Type: multipart/x-api-remote-integration; boundary=remote_send-52124126
  &lt;
  * Closing connection #0
  HTTP/1.1 200 OK
  Date: Mon, 19 Aug 2013 16:00:38 GMT
  Server: Apache/2.2.15 (Red Hat)
  Pragma: no-cache
  CacheControl: no-cache
  Cache-Control: no-cache
  Expires: -1
  Connection: close
  Content-Type: multipart/x-vcg-remote-api; boundary=remote_send-52124126
  
  --remote_send-52124126
  Content-Type: application/x-www-form-urlencoded
  
  result=invalid_filename
  --remote_send-52124126--
  </code></pre>
  
  <p>I know the username and pw data is being read correct by the server as I have tested with erroneous info and received credential error instead.</p>