title: Can anyone give me an example for PHP's CURLFile class?
body: <p>I had a very simple PHP code to upload a file to a remote server; the way I was doing it (as has been suggested here in some other solutions) is to use cUrl to upload the file. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>$ch = curl_init("http://www.remotesite.com/upload.php"); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('fileupload' =&gt; '@'.$_FILES['Filedata']['tmp_name'])); 
  echo curl_exec($ch);        
  </code></pre>
  
  <p>The server is running PHP 5.5.0 and it appears that @filename has been deprecated in PHP >= 5.5.0 as stated <a href="http://www.php.net/manual/en/function.curl-setopt.php" rel="noreferrer">here</a> under the <code>CURLOPT_POSTFIELDS</code> description, and therefore, I'm getting this error:</p>
  
  <pre><code>Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in ... 
  </code></pre>
  
  <p>Interestingly, there is absolutely nothing about this Class on php.net aside from a basic class overview. No examples, no description of methods or properties. It's basically blank <a href="http://www.php.net/manual/en/class.curlfile.php" rel="noreferrer">here</a>. I understand that is a brand new class with little to no documentation and very little real-world use which is why practically nothing relevant is coming up in searches on Google or here on Stackoverflow on this class.</p>
  
  <p>I'm wondering if there's anyone who has used this CURLFile class and can possibly help me or give me an example as to using it in place of @filename in my code.</p>
  
  <p>Edit:</p>
  
  <p>I wanted to add my "upload.php" code as well; this code would work with the traditional @filename method but is no longer working with the CURLFile class code:</p>
  
  <pre><code>$folder = "try/";
  $path = $folder . basename( $_FILES['file']['tmp_name']); 
  if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
  echo "The file ".  basename( $_FILES['file']['tmp_name']). " has been uploaded";
  }
  </code></pre>
  
  <p><strong><em>Final Edit</em></strong>:</p>
  
  <p>Wanted to add Final / Working code for others looking for similar working example of the scarcely-documented CURLFile class ... </p>
  
  <p><strong>curl.php (local server)</strong></p>
  
  <pre><code>&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post" enctype="multipart/form-data"&gt;
  &lt;label for="file"&gt;Filename:&lt;/label&gt; &lt;input type="file" name="Filedata" id="Filedata" /&gt; 
  &lt;br /&gt;
  &lt;input type="submit" name="submit" value="Submit" /&gt;
  &lt;/form&gt;
  
  &lt;?php
  if ($_POST['submit']) {
      $uploadDir = "/uploads/";
      $RealTitleID = $_FILES['Filedata']['name'];
      $ch = curl_init("http://www.remotesite.com/upload.php"); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $args['file'] = new CurlFile($_FILES['Filedata']['tmp_name'],'file/exgpd',$RealTitleID);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $args); 
      $result = curl_exec($ch);       
  }
  ?&gt;
  </code></pre>
  
  <p><strong>upload.php (remote server)</strong></p>
  
  <pre><code>$folder = "try/";
  $path = $folder . $_FILES['file']['name']; 
  if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
  echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";
  } 
  </code></pre>