php curl远程上传到rapidshare

时间:2012-09-21 22:56:32

标签: php curl upload rapidshare

这是一个简单的功能,通过PHP远程上传文件到rapidshare,需要用户名和密码以及服务器中激活的curl。

在哪里是全局的,你可以在函数

之外的任何地方设置用户名和密码
  function upload_Rapidshare_remote($fileurl)
  {
        global $username, $password;

        //Define the variables for post
        $url        = 'http://rapidshare.com/cgi-bin/rsapi.cgi';
        $fields     = array('sub'        => "remotegets",
                             'cmd'       => "addjob",
                             'login'     => $username,
                             'password'  => $password,
                             'urls'      => urlencode($fileurl)
                          );

        //Create url for post data
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        rtrim($fields_string, '&');

        //Open the Connection
        $ch = curl_init($url);

        //Send Post Data
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

        //Execute
        $result = curl_exec($ch);

        //Close the connection
        curl_close($ch);

        //return....
        return;
  }

使用方法

upload_Rapidshare_remote('http://www.mysite.com/file.zip');

0 个答案:

没有答案