通过他们的API使用PHP和卷曲文件上传到搜索RapidShare [英] Uploading files to RapidShare using PHP and cURL via their API

查看:137
本文介绍了通过他们的API使用PHP和卷曲文件上传到搜索RapidShare的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用上传他们与卷曲的API和PHP文件搜索RapidShare。到目前为止,我这有code:

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);

但我得到的唯一回应是:错误:子程序无效。 (b6ba5d82)。如果我只是这样做(基本上不与发送请求的文件):

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);

我得到这样的答复:错误:没有传送的文件。 (f269d341)

所以我猜有什么毛病,我通过POST发送文件的方式。

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

任何人都知道可能是错的?

Anyone know what could be wrong?

感谢您。

推荐答案

添加卷曲参数

    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.

这篇关于通过他们的API使用PHP和卷曲文件上传到搜索RapidShare的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆