server/files/ajax/delete.php
2011-04-18 16:48:35 +02:00

36 lines
889 B
PHP

<?php
// Init owncloud
require_once('../../lib/base.php');
// We send json data
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn()){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}
// Get data
$dir = $_GET["dir"];
$files = isset($_GET["file"]) ? $_GET["file"] : $_GET["files"];
$files = explode(';', $files);
$filesWithError = '';
$status = 'success';
//Now delete
foreach($files as $file) {
if( !OC_FILES::delete( $dir, $file )){
$filesWithError .= $file . "\n";
$status = 'error';
}
}
if($status == 'success') {
echo json_encode( array( "status" => $status, "data" => array( "dir" => $dir, "files" => $files )));
} else {
echo json_encode( array( "status" => $status, "data" => array( "message" => "Could not delete:\n" . $filesWithError )));
}
?>