kleiram / transmission-php

PHP Transmission API client
Other
184 stars 62 forks source link

Lib inclusion and authenticating/connecting. #64

Closed darkcloud784 closed 7 years ago

darkcloud784 commented 7 years ago

Hello,

I'm VERY new to coding in general but have been working on a home dashboard for my homelab. Anyway, I seem to be having an issue authenticating and connecting to my transmission server. below is my code, I have all the values setup in config.php in an array for easy changes.

       include 'config.php'; 
        $host = $cfg_array['Torrent_Server_IP'];
        $port = $cfg_array['Torrent_Server_Port'];
        $username = $cfg_array['Torrent_username'];
        $password = $cfg_array['Torrent_password'];
        // Include Transmission 

        require_once __DIR__.'/../vendor/autoload.php';
        $client = new Client();
        $client->authenticate($username, $password);
        $transmission = new Transmission($host, $port);
        $transmission->setClient($client);
        ?>

        <div class="row">
            <!--Downloading Section-->
            <div class="col-lg-6 col-md-3 col-sm-12 col-xs-12">
                <div class="info-box blue-bg">
                    <h3>Downloading</h3>
<?php
$queue = $transmission->all();
echo "Downloading to: {$transmission->getSession()->getDownloadDir()}\n";
foreach ($queue as $torrent) {
    echo "{$torrent->getName()}";
    if ($torrent->isFinished()) {
        echo ": done\n";
    } else {
        if ($torrent->isDownloading()) {
            echo ": {$torrent->getPercentDone()}% ";
            echo "(eta: " . gmdate("H:i:s", $torrent->getEta()) . ")\n";
        } else {
            echo ": paused\n";
        }
    }
}
?>

                </div>
            </div>

    </body>
</html>

My error from the server:

[Tue Nov 29 10:47:44.230019 2016] [:error] [pid 10068] [client localhost:50418] PHP Fatal error: require_once(): Failed opening required '/var/www/html/../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/html/main.php on line 25, referer: redacted/

Singman33 commented 7 years ago

Try to use require_once __DIR__.'/vendor/autoload.php' instead, or any localtion where composer put your files after composer install

afk11 commented 7 years ago

Your include path says __DIR__ . "/../vendor/autoload.php" meaning /var/www, but I'm guessing your composer.json & vendor directory are in /var/www/html. Change the require_once line as was suggested above.

FYI - you should create a public folder, to put in all your public facing PHP code that the webserver can access. Keep the folder with composer.json one directory lower than the webroot, so your packages & git & config.php aren't exposed to the web.

You could leave your project in /var/www/html, then just configure your webserver to use /var/www/html/public as the webroot.