1

I'm trying to use Rapidshare's API to download a file. To do so, I need to request their download subroutine twice. Once to get the appropriate download server to use, and secondly to request the download again on the server that the first request gave me. The second call is what sends the file.

On the first call, it returns a header with a Location: blah field, and I need to follow this location. So I did this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=$file_id&filename=$file_name&try=1&login={$account['username']}&password={$account['password']}");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$resp = curl_exec($ch);
curl_close($ch);

Unfortunately, it doesn't seem to be following the location header, because nothing is being returned in $resp. If I put the URL in my browser, it successfully follows the location header and gives me the output of the API call, so it must be something wrong with PHP or cURL.

Can anyone hazard a guess on what it might be? I've been fiddling for 30 minutes minutes now and have no idea.

Thanks for any help!

Josh
  • 1,361
  • 5
  • 22
  • 33
  • Is your PHP in safe mode? http://www.edmondscommerce.co.uk/curl/php-curl-curlopt_followlocation-and-open_basedir-or-safe-mode/ – Michael Mior May 26 '11 at 18:15
  • Try enabling CURLOPT_HEADER so the response's headers are included in `$resp`. If RS is using a javascript/meta redirect instead of a header-based one, curl won't pick up on that and you'd have to parse that out manually. – Marc B May 26 '11 at 18:21
  • have you tried to access the generated url? –  May 26 '11 at 18:21

1 Answers1

1

change the CURLOPT_HEADER to true.

curl_setopt($ch, CURLOPT_HEADER, 1);

If I've read the documentation right, that will return the requested page's heaader, with contains the "Location" Directive, and by having CURLOPT_FOLLOWLOCATION set to true it should follow that redirect, and any others via the Location directive.

aczietlow
  • 566
  • 6
  • 6