zzarbi / synology

PHP Implementation of Synology Download Station
MIT License
125 stars 58 forks source link

Example for DSM #1

Closed Bojhan closed 10 years ago

Bojhan commented 10 years ago

Hi,

I am trying to use this, but its a little hard. Since the demo is quite limited, wondering if you have any examples for retrieving things like the directory and files with some timestamps. Right now this library seems limited to primary the Download Manager it would be nice if it could do more generic stuff.

zzarbi commented 10 years ago

Hi,

I just tried it and it seems fine to me. I tried getInfo with AudioStation and DownloadStation. First how are you running the script? Through you're browser or via command line?

Then I'm guessing the autoload might be the problem, I'm using "include" instead of "require" which might just throw a notice, which you might not see depending on your PHP settings. Try the following code and check if the new include path looks ok, meaning are all the "/" look like "/" and not "\". Also here I'm using require instead of include and this will throw a fatal error if it's not working:

echo 'Include_path = '.get_include_path().PHP_EOL;
echo 'path_separator = '.PATH_SEPARATOR.PHP_EOL;
set_include_path(dirname(__FILE__).'/library'.PATH_SEPARATOR.get_include_path());
echo 'New Include_path = '.get_include_path().PHP_EOL.PHP_EOL;

function __autoload($class_name) {
    $path = str_replace('_', DIRECTORY_SEPARATOR, $class_name);
    echo 'Loading: '.$class_name.' => '.$path.'.php'.PHP_EOL;
    require($path . '.php');
}
$synology = new Synology_DownloadStation_Api('192.168.10.5', 5000, 'http', 1);
echo 'Great'.PHP_EOL;

My output look like that:

Include_path = .:
path_separator = :
New Include_path = /Users/zzarbi/pool/synology/library:.:

Loading: Synology_DownloadStation_Api => Synology/DownloadStation/Api.php
Loading: Synology_Api_Authenticate => Synology/Api/Authenticate.php
Loading: Synology_Abstract => Synology/Abstract.php
Loading: Synology_Api => Synology/Api.php
Great
Bojhan commented 10 years ago

Wow, thanks for your timely response! I tried it and, figured out where my error was. Very helpful!

I think I slightly misunderstood the purpose of this project. I imagined it provided a implementation of the FileStation API, something I haven't seen anywhere else. My goal is retrieve all the files in a folder, list them on the page (browser) and allow users to download the files (save as). Do you expect to still add this feature?

I have been trying to implement a new API using your framework, but so far been unsuccessful.

zzarbi commented 10 years ago

Hi,

I just implement just that (717804eeddacde619d792532cc9bef3c29fa185c). With the last code you can get a list of shares for FileStation:

$synology = new Synology_FileStation_Api('192.168.10.5', 5000, 'http', 1);
$synology->activateDebug();
$synology->connect('admin', 'xxx');
print_r($synology->getShares());

Get a list of files:

print_r($synology->getList('/home'));

And download one file:

// need to disable debug
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="test.txt"'); //<<< Note the " " surrounding the file name
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo $synology->download('/home/text.txt');

This should work in a browser, altho i didnt test it. You can continue the implementation if you want using this PDF (http://ukdl.synology.com/download/Document/DeveloperGuide/Synology_File_Station_API_Guide.pdf)

Bojhan commented 10 years ago

I can confirm that it works beautifully. I simply use the function to do the following:

foreach ($listing->files as $file) {
$file->name;
$file->path;
}

It probally makes sense to add this to your Read.me and you could also trow it in the example.