示例#1
0
 protected function act_rm_cbd()
 {
     if (!$this->config['access']['files']['delete'] || !isset($this->post['files']) || !is_array($this->post['files']) || !count($this->post['files'])) {
         $this->errorMsg("Unknown error.");
     }
     $error = array();
     foreach ($this->post['files'] as $file) {
         $file = path::normalize($file);
         if (substr($file, 0, 1) == ".") {
             continue;
         }
         $type = explode("/", $file);
         $type = $type[0];
         if ($type != $this->type) {
             continue;
         }
         $path = "{$this->config['uploadDir']}/{$file}";
         $base = basename($file);
         $replace = array('file' => $base);
         if (!is_file($path)) {
             $error[] = $this->label("The file '{file}' does not exist.", $replace);
         } elseif (!@unlink($path)) {
             $error[] = $this->label("Cannot delete '{file}'.", $replace);
         } else {
             $thumb = "{$this->thumbsDir}/{$file}";
             if (is_file($thumb)) {
                 @unlink($thumb);
             }
             // Couch thumbs
             $thumbs = dir::get_couch_thumbs($path);
             foreach ($thumbs as $thumb) {
                 @unlink($thumb);
             }
         }
     }
     if (count($error)) {
         return json_encode(array('error' => $error));
     }
     return true;
 }