title: Sending File with cURL
body: <p>I've sent some post data with cURL and am now trying to send a file, getting lost along the way. I'm using a form with a file input. Then would like cURL to send it off to my server. Here is my upload page.
      <code>&lt;form action="curl_page.php" method="post" enctype="multipart/form-data"&gt;
      Filename: &lt;input type="file" name="file" id="file" /&gt; &lt;br /&gt;
      &lt;input type="submit" name="submit" value="Submit" /&gt;
      &lt;/form&gt;</code></p>
  
  <p>Here is my curl page with some issues.</p>
  
  <pre><code>&lt;?php
  $tmpfile = $_FILES['file']['tmp_name'];
  $filename = basename($_FILES['file']['name']);
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "http://my_server/file_catch.php");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, true);
  $data = array(
      'uploaded_file' =&gt; '@'.$tmpfile.';filename='.$filename,
  );
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  $output = curl_exec($ch);
  curl_close($ch);
  ?&gt;
  </code></pre>
  
  <p>The file_catch.php on my server looks like this.</p>
  
  <pre><code>&lt;?php
  $folder = "audio/";
  
  $path = $folder . basename( $_FILES['file']['name']);
  
  if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
      echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";
  } else{
      echo "There was an error uploading the file, please try again!";
  }
  ?&gt;
  </code></pre>
  
  <p>Thanks for any help!</p>