title: Send file via cURL from form POST in PHP
body: <p>I'm writing an API and I'm wanting to handle file uploads from a form <code>POST</code>. The markup for the form is nothing too complex:</p>
  
  <pre><code>&lt;form action="" method="post" enctype="multipart/form-data"&gt;
    &lt;fieldset&gt;
      &lt;input type="file" name="image" id="image" /&gt;
      &lt;input type="submit" name="upload" value="Upload" /&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>However, I'm having difficulties understanding how to handle this server-side and send along with a cURL request.</p>
  
  <p>I'm familiar with sending <code>POST</code> requests with cURL with a data array, and resources I've read on uploading files tell me to prefix the filename with an <code>@</code> symbol. But these same resources have a hard-coded file name, e.g.</p>
  
  <pre><code>$post = array(
      'image' =&gt; '@/path/to/myfile.jpg',
      ...
  );
  </code></pre>
  
  <p>Well which file path is this? Where would I find it? Would it be something like <code>$_FILES['image']['tmp_name']</code>, in which case my <code>$post</code> array should look like this:</p>
  
  <pre><code>$post = array(
      'image' =&gt; '@' . $_FILES['image']['tmp_name'],
      ...
  );
  </code></pre>
  
  <p>Or am I going about this the wrong way? Any advice would be most appreciated.</p>
  
  <p><strong>EDIT:</strong> If someone could give me a code snippet of where I would go with the following code snippets then I'd be most grateful. I'm mainly after what I would send as cURL parameters, and a sample of how to use those parameters with the receiving script (let's call it <code>curl_receiver.php</code> for argument's sake).</p>
  
  <p>I have this web form:</p>
  
  <pre><code>&lt;form action="script.php" method="post" enctype="multipart/form-data"&gt;
    &lt;fieldset&gt;
      &lt;input type="file" name="image /&gt;
      &lt;input type="submit" name="upload" value="Upload" /&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And this would be <code>script.php</code>:</p>
  
  <pre><code>if (isset($_POST['upload'])) {
      // cURL call would go here
      // my tmp. file would be $_FILES['image']['tmp_name'], and
      // the filename would be $_FILES['image']['name']
  }
  </code></pre>