You are here

public function DefaultController::demo_download in Demonstration site (Sandbox / Snapshot) 8

Funtion to download the dump file.

1 string reference to 'DefaultController::demo_download'
demo.routing.yml in ./demo.routing.yml
demo.routing.yml

File

src/Controller/DefaultController.php, line 35

Class

DefaultController
Default controller for the demo module.

Namespace

Drupal\demo\Controller

Code

public function demo_download($filename, $type) {
  $fileconfig = demo_get_fileconfig($filename);
  if (!isset($fileconfig[$type . 'file']) || !file_exists($fileconfig[$type . 'file'])) {
    return MENU_NOT_FOUND;
  }

  // Force the client to re-download and trigger a file save download.
  $headers = [
    'Cache-Control: private',
    'Content-Type: application/octet-stream',
    'Content-Length: ' . filesize($fileconfig[$type . 'file']),
    'Content-Disposition: attachment, filename=' . $fileconfig[$type],
  ];
  return new BinaryFileResponse($fileconfig[$type . 'file'], 200, $headers);
}