Jump to content

Recommended Posts

Hi, i need to do a loop of the array of this function found in the WebUI API:

public function getTorrents()

 

 

WebUI API: http://pastebin.com/m76205d0b

 

 

I have this one, but it doesn't work.

 

$utorrent = new uTorrent();
$utorrent->host = $_SESSION['host'];
$utorrent->user = $_SESSION["user"];
$utorrent->pass = $_SESSION["pass"];
$torrents = $utorrent->getTorrents();

foreach($torrents as $torrent) {
    echo $torrent[uTORRENT_TORRENT_NAME]."\n";
}

 

How do i use the "public function getTorrents()" to get the array into a foreach loop?

 

I really appreciate your help ;)

 

 

It seems like it's returning JSON. You can use json_decode() to turn it into an array.

 

 

Yes, take a look at this bit of the WebUI at the bottom:

it gets and decodes the json, what i need i a method to get the array from "public function getTorrents()" and get it into a foreach loop.

 

Do you think you can help me with that?

 

 

 

// performs request
    private function makeRequest($action, $decode = true, $options = array()) {
        $ch = curl_init();
        curl_setopt_array($ch, $options);
        curl_setopt($ch, CURLOPT_URL, "http://".$this->host."/gui/".$action);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERPWD, $this->user.":".$this->pass);
        $req = curl_exec($ch);
        curl_close($ch);

        return ($decode ? json_decode($req, true) : $req);
    }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.