title: How to convert HTML upload form to PHP/cURL function
body: <p><strong>Update: scroll for my solution.</strong></p>
  
  <p>This <a href="https://youdbox.com/" rel="nofollow noreferrer">site</a> has <a href="https://youdbox.docs.apiary.io/#reference/upload" rel="nofollow noreferrer">API access</a> to upload files directly to its servers
  and I success to perform all API calls using cURL post/get
  but unfortunately, in the upload stage he provided only HTML form.</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="https://s1.youdbox.com/upload/01" method="post"&gt;
  &lt;input name="sess_id" value="3qr5wkukoy31pd1g"&gt;
  &lt;input name="file" type="file"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I tried many times to figure out how to perform upload using cURL post but it always failed
  But when I create a HTML file and use the above upload form then add the upload data manually
  it success and works fine</p>
  
  <pre><code>$ch1 = curl_init();
  curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch1, CURLOPT_URL, $server_url);
  curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch1, CURLOPT_POST, 1);
  
  $upload_data = array(
      'sess_id' =&gt; $sesson_id,
      #'file' =&gt; '@' .realpath('test.txt')
      'file'    =&gt; $file
  );
  
  $headers = array();
  $headers[] = 'multipart/form-data';
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  
  curl_setopt($ch1, CURLOPT_POSTFIELDS, $upload_data);
  
  $up_result = curl_exec($ch1);
  if (curl_errno($ch1)) {
      echo 'Error:' . curl_error($ch1);
  }
  curl_close($ch1);
  
  var_dump($up_result);
  </code></pre>