Uploading files to RapidShare using PHP and cURL via their API

只谈情不闲聊 提交于 2019-12-13 04:45:34

问题


I'm trying to upload files to RapidShare using their API and PHP with cURL. So far, I've got this 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 .= '&login=login';
$url .= '&password=mypass';
$url .= '&filename=' . $filename;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
// Set post fields
$postFields = array('filecontent' => array('@' . $targetDir . '/' . $id));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$resp = curl_exec($ch);

die($resp);

But the only response I get is: ERROR: Subroutine invalid. (b6ba5d82). If I just do this (basically don't send the file with the request):

// Upload the file to RapidShare
$url = 'http://rs' . $uploadServer . '.rapidshare.com/cgi-bin/rsapi.cgi?sub=upload';
$url .= '&login=login';
$url .= '&password=mypass';
$url .= '&filename=' . $filename;
curl_setopt($ch, CURLOPT_URL, $url);
$resp = curl_exec($ch);

I get this response: ERROR: No files transmitted. (f269d341)

So I'm guessing there's something wrong with the way I'm sending the file via POST.

Anyone know what could be wrong?

Thank you.


回答1:


Add curl parameter

    curl_setopt($ch, CURLOPT_INFILESIZE,(string)filesize($filename));
    curl_setopt($ch, CURLOPT_INFILE,fopen($filename,'r'));

and $filename must write full path. Sorry Im english very little.




回答2:


Oddly enough, i just hit this problem as well. after trying for an hour or two to find out what's wrong, it turned out to be quite simple and caused by ignoring a single statement in the api document : "GET parameters are ignored if the POST method is used. So if you use the POST method, send ALL parameters via POST." for upload to work, sub=upload should also be sent as a POST parameter rather than GET.



来源:https://stackoverflow.com/questions/10987651/uploading-files-to-rapidshare-using-php-and-curl-via-their-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!