Ejemplo n.º 1
0
 function serveFile()
 {
     if ($this->missingParams()) {
         $this->error("Required parameters are missing");
     } else {
         if ($this->checkPermissions()) {
             $tc = new ThorCore("", $this->table);
             if ($this->mode == "fetch_zip") {
                 $path = $this->zipfile;
                 $matches = array();
                 $res = preg_match("/.*_(form_.*)/", $this->zipfile, $matches);
                 $attachmentFilename = count($matches) == 2 ? $matches[1] : "thor_archive.zip";
             } else {
                 $path = $tc->construct_file_storage_location($this->row, $this->col, $this->filename);
                 $attachmentFilename = $this->filename;
             }
             if (!file_exists($path)) {
                 $this->error("Unable to find this file");
             } else {
                 header('Content-disposition: attachment; filename=' . $attachmentFilename);
                 // header('Content-type: text/plain');
                 readfile($path);
                 if ($this->mode == "fetch_zip") {
                     ignore_user_abort(true);
                     if (connection_aborted()) {
                         unlink($this->zipfile);
                     }
                     unlink($this->zipfile);
                 }
             }
         } else {
             $this->error("You do not have permissions to access this file.");
         }
     }
 }