title: How to convert curl file post from command line into PHP cURL
body: <p>I'm trying to post files to a 3rd party API from my PHP app.
  This works from the command line:</p>
  
  <pre><code>curl -F "file=@move_file.MOV" "https://upload.wistia.com?project_id=pbmcmua3ot&amp;username=api&amp;api_password=xxxxx_apikey_yyyyy"
  </code></pre>
  
  <p>But I can't get it to work using PHP's curl:</p>
  
  <pre><code>    $data = array(
          'username'      =&gt; $username,
          'api_password'  =&gt; $api_password,
          'file'          =&gt; fopen($tmp_filename, 'r'),
          'project_id'    =&gt; $project_hashed_id,
          );
  
  
      $ch = curl_init();
      //curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, "https://upload.wistia.com" );
      curl_setopt($ch, CURLOPT_UPLOAD, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeout
  
      curl_setopt($ch, CURLOPT_INFILE, fopen($tmp_filename, 'r') );
      curl_setopt($ch, CURLOPT_NOPROGRESS, false);
      curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
      curl_setopt($ch, CURLOPT_INFILESIZE, filesize($tmp_filename));
  
      curl_setopt($ch, CURLOPT_VERBOSE, 1); //for debugging
      curl_setopt($ch, CURLOPT_HEADER, true);
  
      curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  
      $result = curl_exec($ch);
      curl_close($ch);
      return json_decode($result);
  </code></pre>
  
  <p>I think <code>CURLOPT_INFILE</code> is the problem but I'm not sure. Thanks in advance for any help you can give me.</p>
  
  <p><strong>UPDATE1</strong></p>
  
  <pre><code>    $data = array(
          'username'      =&gt; $username,
          'api_password'  =&gt; $api_password,
          'file'          =&gt; '@'.$tmp_filename,
          'project_id'    =&gt; $project_hashed_id,
          );
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, "https://upload.wistia.com" );
      curl_setopt($ch, CURLOPT_UPLOAD, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeout
      curl_setopt($ch, CURLOPT_NOPROGRESS, false);
      curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
      curl_setopt($ch, CURLOPT_INFILESIZE, filesize($tmp_filename));
      curl_setopt($ch, CURLOPT_VERBOSE, 1); //for debugging
      curl_setopt($ch, CURLOPT_HEADER, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  
      $result = curl_exec($ch);
      curl_close($ch);
      return json_decode($result);
  </code></pre>
  
  <p><strong>UPDATE 2 (Working)</strong></p>
  
  <pre><code>    $data = array(
          'api_password'  =&gt; $api_password,
          'file'          =&gt; '@'.$tmp_filename,
          'project_id'    =&gt; $project_id
          );
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_URL, "https://upload.wistia.com" );
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);    
      $result = curl_exec($ch);
      curl_close($ch);
  </code></pre>