title: PHP Curl upload file through Post Data
body: <p>How would I go by submitting a file that in the same directory as this script inside the <code>$data</code>. The below function is what I currently use. If you find any bugs in the current code please tell me as well.</p>
  
  <pre><code>function post_data($site,$data){
      $datapost = curl_init();
   $headers = array("Expect:");
      curl_setopt($datapost, CURLOPT_URL, $site);
   curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
      curl_setopt($datapost, CURLOPT_HEADER, TRUE);
   curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers); 
      curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      curl_setopt($datapost, CURLOPT_POST, TRUE);
      curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
       curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
      ob_start();
      return curl_exec ($datapost);
      ob_end_clean();
      curl_close ($datapost);
      unset($datapost);    
  }
  </code></pre>