emscripten Humble Cloud interface
Edward Rudd
2014-08-30 cd8c67b18fecf9d648aca1a58177fceec128788e

implement deletion of files in the sample server

3 files modified
33 ■■■■■ changed files
server/src/Custom/CorsClient.php 2 ●●● patch | view | raw | blame | history
server/src/DB/DA.php 8 ●●●●● patch | view | raw | blame | history
server/src/RestAPI/Storage.php 23 ●●●●● patch | view | raw | blame | history
server/src/Custom/CorsClient.php
@@ -5,7 +5,7 @@
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);
    }
server/src/DB/DA.php
@@ -76,6 +76,14 @@
        $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
server/src/RestAPI/Storage.php
@@ -60,6 +60,29 @@
        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