Delete a document
delete
DELETE https://collaboractor.com/api/v1/delete/file?login=&password=
file is the name of the file in your personal space to delete.
login | Your identification code. |
---|---|
password | Your password. |
NOTE: A POST is accepted.
$ curl -D - -X DELETE "https://collaboractor.com/api/v1/delete/file_sample_500kB.doc?login=abcdef&password=ABCDEF"
If 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 senddelete
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 senddelete
function.
Add the file filedelete.php with the following content:
- require_once 'sendhttp.php';
Loads the code of the senddelete
function.
- function file_delete($login, $password, $filename) {
Defines the function file_delete
.
$login
is your identification code. $password
is your password.
$filename
is the name of the file to delete.
- $curl = 'https://collaboractor.com/api/v1/delete/' . urlencode($filename) . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);
Sets $curl
to the URL of the delete action with the name of the file, the identification code and the password of the user's account.
$filename
, $login
and $password
must be escaped.
- $response=senddelete($curl);
Sends the HTTP request with senddelete
.
The arguments $filename
, login
and password
are already in $curl
.
- 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_delete
returns false.
- return true;
- }
Returns true
if the document has been deleted from your personal space.
EXAMPLE
Assuming you have saved the files sendhttp.php and filedelete.php in the current directory, run PHP in interactive mode, load the file_delete
function and call it with as arguments your identification code and password, the name of the file to delete:
$ php -a
php > require_once 'filedelete.php';
php > echo file_delete('abcdef', 'ABCDEF', 'file_sample_500kB.doc') ? 'Ok' : 'Ko';
Ok
php > quit
NOTE: If file_delete
returns false
, edit the code to display $response
.
Comments