title: How to upload files with POST form-data in PHP?
body: <p>The normal <code>curl</code> way, works well.</p>
  
  <pre class="lang-sh prettyprint-override"><code>curl \
    -F "smfile=@test.png" \
    -H "Content-Type: multipart/form-data" \
    https://sm.ms/api/v2/upload
  </code></pre>
  
  <p>But in my PHP version curl, it returns <code>bool(false)</code> and <code>string(0) ""</code>:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  $url = "https://sm.ms/api/v2/upload";
  $headers = array();
  array_push($headers, "Content-Type: multipart/form-data");
  array_push($headers, "User-Agent: ".$_SERVER['HTTP_USER_AGENT']);
  
  // $fields = array('smfile' =&gt; curl_file_create('test.png', 'image/png', 'test.png'));
  $fields = array('smfile' =&gt; new CURLFile('test.png', 'image/png', 'tset.png'));
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  
  var_dump(curl_exec($ch));
  var_dump(curl_error($ch));
  
  </code></pre>
  
  <p>What's wrong with my code? <code>ヽ(*。&gt;Д&lt;)o゜</code></p>