예제 #1
0
 public function testUpdate()
 {
     $fdao = new FilesDao();
     $file = new File();
     $file->fid = "testfid";
     $file->name = "testname";
     $fdao->save($file);
     $res = $fdao->getByFid("testfid");
     $this->assertGreaterThan(0, $res);
     $dfile = $res;
     $dfile->name = "changedname";
     $fdao->save($dfile);
     $mfile = $fdao->getById($dfile->id);
     $this->assertEquals("changedname", $mfile->name);
 }
예제 #2
0
 protected function download()
 {
     if (!getSession()->isPremium()) {
         die("Upgrade your logboost account to premium to be able to download files");
     }
     switch ($this->options['download_via_php']) {
         case 1:
             $redirect_header = null;
             break;
         case 2:
             $redirect_header = 'X-Sendfile';
             break;
         case 3:
             $redirect_header = 'X-Accel-Redirect';
             break;
         default:
             return $this->header('HTTP/1.1 403 Forbidden');
     }
     $file_name = $this->get_file_name_param();
     if (!$this->is_valid_file_object($file_name)) {
         return $this->header('HTTP/1.1 404 Not Found');
     }
     if ($redirect_header) {
         return $this->header($redirect_header . ': ' . $this->get_download_url($file_name, $this->get_version_param(), true));
     }
     $fdao = new FilesDao();
     $dfile = $fdao->getByFid($file_name);
     $dfile->usage = $dfile->usage + 1;
     $dfile->lastusagedate = @date('c');
     $fdao->save($dfile);
     if ($dfile === null) {
         return $this->header('HTTP/1.1 404 Not Found');
     }
     $file_path = $this->get_upload_path($file_name, $this->get_version_param());
     // Prevent browsers from MIME-sniffing the content-type:
     $this->header('X-Content-Type-Options: nosniff');
     if (!preg_match($this->options['inline_file_types'], $file_name)) {
         $this->header('Content-Type: application/octet-stream');
         $this->header('Content-Disposition: attachment; filename="' . $dfile->name . '"');
     } else {
         $this->header('Content-Type: ' . $dfile->type);
         $this->header('Content-Disposition: inline; filename="' . $dfile->name . '"');
     }
     $this->header('Content-Length: ' . $this->get_file_size($file_path));
     $this->header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', filemtime($file_path)));
     $this->readfile($file_path);
 }