title: Uploading files to RapidShare using PHP and cURL via their API
body: <p>I'm trying to upload files to RapidShare using their API and PHP with cURL. So far, I've got this code:</p>
  
  <pre><code>// Get the RapidShare server to upload to
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver');
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $uploadServer = curl_exec($ch);
  
  // Upload the file to RapidShare
  $url = 'http://rs' . $uploadServer . '.rapidshare.com/cgi-bin/rsapi.cgi?sub=upload';
  $url .= '&amp;login=login';
  $url .= '&amp;password=mypass';
  $url .= '&amp;filename=' . $filename;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  // Set post fields
  $postFields = array('filecontent' =&gt; array('@' . $targetDir . '/' . $id));
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  $resp = curl_exec($ch);
  
  die($resp);
  </code></pre>
  
  <p>But the only response I get is: <code>ERROR: Subroutine invalid. (b6ba5d82)</code>. If I just do this (basically don't send the file with the request):</p>
  
  <pre><code>// Upload the file to RapidShare
  $url = 'http://rs' . $uploadServer . '.rapidshare.com/cgi-bin/rsapi.cgi?sub=upload';
  $url .= '&amp;login=login';
  $url .= '&amp;password=mypass';
  $url .= '&amp;filename=' . $filename;
  curl_setopt($ch, CURLOPT_URL, $url);
  $resp = curl_exec($ch);
  </code></pre>
  
  <p>I get this response: <code>ERROR: No files transmitted. (f269d341)</code></p>
  
  <p>So I'm guessing there's something wrong with the way I'm sending the file via POST.</p>
  
  <p>Anyone know what could be wrong?</p>
  
  <p>Thank you.</p>