Download a document
download
GET https://collaboractor.com/api/v1/download/file?login=&password=&lang=
file is the name of the file in your personal space to download.
| login | Your identification code. | 
|---|---|
| password | Your password. | 
$ curl -X GET "https://collaboractor.com/api/v1/download/file_sample_500kB.doc"?login=abcdef&password=ABCDEF" > file_sample_500kB.docIf the file name is invalid, the service returns the error HTTP/1.1 400 Bad Request.
If no file has the specified name in your personal space, the service returns the error HTTP/1.1 404 Not Found.
Download the code of the sendget function from the iZend library.
Copy the file in the space of your application.
NOTE: See the page Call the service API for a description of the sendget function.
Add the file filedownload.php with the following content:
- require_once 'sendhttp.php';
Loads the code of the sendget function.
- function file_download($login, $password, $filename) {
Defines the function file_download.
$login is your identification code. $password is your password.
$filename is the name of the file to download.
- $curl = 'https://collaboractor.com/api/v1/download/' . urlencode($filename);
Sets $curl to the URL of the download action with the name of the file to download.
- $args = array(
- 'login' => $login,
- 'password' => $password,
- );
Prepares the list of arguments of the GET: the identification code and the password of the user's account.
- $response=sendget($curl, $args);
Sends the HTTP request with sendget.
- if (!$response or $response[0] != 200) {
- return false;
- }
If $response is false, the server is unreachable.
If $response[0] doesn't contain the HTTP return code 200 Ok, an execution error has occurred.
In case of error, file_download returns false.
- return file_put_contents($filename, $response[2]);
- }
Saves the document in a file with the same name in the current directory.
Returns true if the file has been created properly, false otherwise. 
EXAMPLE
Assuming you have saved the files sendhttp.php and filedownload.php in the current directory, run PHP in interactive mode, load the file_download function and call it with as arguments your identification code and password, the name of the file to download:
$ php -a
php > require_once 'filedownload.php';
php > echo file_download('abcdef', 'ABCDEF', 'file_sample_500kB.doc') ? 'Ok' : 'Ko';
Ok
php > quitCheck the document:
$ libreoffice file_sample_500kB.doc NOTE: If file_download returns false, edit the code to display $response.

Comments