implement deletion of files in the sample server
| | |
| | | class CorsClient extends \RestService\Client { |
| | | public function sendResponse($pHttpCode = '200', $pMessage) |
| | | { |
| | | header("Access-Control-Allow-Methods: GET, PUT"); |
| | | header("Access-Control-Allow-Methods: GET, PUT, DELETE"); |
| | | header("Access-Control-Allow-Origin: *"); |
| | | parent::sendResponse($pHttpCode, $pMessage); |
| | | } |
| | |
| | | $stmt->execute(array($size, $timestamp, $path, $name)); |
| | | return true; |
| | | } |
| | | |
| | | public function removeFile($id) |
| | | { |
| | | $this->connect(); |
| | | $stmt = $this->pdo->prepare("DELETE FROM files WHERE id = ?"); |
| | | $stmt->execute(array($id)); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | // vim: ts=4 et |
| | |
| | | |
| | | return array('url' => '/files/' . $id); |
| | | } |
| | | |
| | | /** |
| | | * @param string path |
| | | * @url files/(.+) |
| | | */ |
| | | function deleteFiles($path) |
| | | { |
| | | $dir = dirname($path); |
| | | $name = basename($path); |
| | | if ($dir == '.') $dir = ''; |
| | | |
| | | $id = $this->da->getFile($dir, $name); |
| | | if (!empty($id)) { |
| | | $this->da->removeFile($id); |
| | | |
| | | $localfilename = dirname($_SERVER['SCRIPT_FILENAME']) . '/files/' . $id; |
| | | |
| | | unlink($localfilename); |
| | | |
| | | return array('success' => true); |
| | | } |
| | | return array('path' => $path, 'error'=>'Could not find file'); |
| | | } |
| | | } |
| | | |
| | | // vim: ts=4 et |