7

Upload a document

upload

POST https://collaboractor.com/api/v1/upload?login=&password=

loginYour identification code.
passwordYour password.
multipart/form-data
fileContent of the document in binary.
$ curl -D - -X POST "https://collaboractor.com/api/v1/upload?login=abcdef&password=ABCDEF" -F "file=@file_sample_500kB.doc;type=application/msword"

NOTE: Use a command such as file -ib file_sample_500kB.doc to obtain the MIME type of the file passed with the argument file.

If the file name is invalid or if the type of the file isn't supported or if the size of the file is greater than the maximum size of a file in your personal space, the service returns the error HTTP/1.1 400 Bad Request.

if the number of files in your personal space has reached the authorized limit, the service returns the error HTTP/1.1 403 Forbidden.

If a file with the same name already exists in your personal space, the service returns the error HTTP/1.1 409 Conflict.

Download the code of the sendpost and file_mime_type functions from the iZend library. Copy the files in the space of your application.

NOTE: See the page Call the service API for a description of the sendpost and file_mime_type functions.

Add the file fileupload.php with the following content:

  1. require_once 'sendhttp.php';
  2. require_once 'filemimetype.php';

Loads the code of the sendpost and file_mime_type functions.

  1. function file_upload($login, $password, $file) {

Defines the function file_upload. $login is your identification code. $password is your password. $file is the pathname of the document to upload.

  1.     $curl = 'https://collaboractor.com/api/v1/upload' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);

Sets $curl to the URL of the upload action with the identification code and the password of the user's account. $login and $password must be escaped.

  1.     $files=array('file' => array('name' => basename($file), 'tmp_name' => $file, 'type' => file_mime_type($file)));

Prepares the list of files attached to the POST: file - the document with the name of the file, the pathname of the file and its MIME type.

  1.     $response=sendpost($curl, false, $files);

Sends the HTTP request with sendpost. The arguments login and password are already in $curl.

  1.     if (!$response or $response[0] != 200) {
  2.         return false;
  3.     }

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_upload returns false.

  1.     return true;
  2. }

Returns true if the document has been added into your personal space.

EXAMPLE

Assuming you have saved the files sendhttp.php, filemimetype.php and fileupload.php in the current directory, run PHP in interactive mode, load the file_upload function and call it with as arguments your identification code and password, the pathname of document managed by LibreOffice:

$ php -a
php > require_once 'fileupload.php';
php > echo file_upload('abcdef', 'ABCDEF', 'file_sample_500kB.doc') ? 'Ok' : 'Ko';
Ok
php > quit

NOTE: If file_upload returns false, edit the code to display $response.

SEE ALSO

Call the service API, Edit a document, Download a document, Delete a document

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].