You are here

function download_file_direct_download in DownloadFile 7.3

Same name and namespace in other branches
  1. 6 download_file.module \download_file_direct_download()
  2. 7 download_file.module \download_file_direct_download()
  3. 7.2 download_file.module \download_file_direct_download()

Page who forces the download of the file by changing the header.

Parameters

stdClass $file:

Return value

int|null

1 string reference to 'download_file_direct_download'
download_file_menu in ./download_file.module
Implementation of hook_menu().

File

./download_file.module, line 145
Module to direct download files or images.

Code

function download_file_direct_download(stdClass $file) {
  $headers = file_download_headers($file->uri);
  if (!$headers) {
    return MENU_ACCESS_DENIED;
  }
  $default_headers = array(
    'Content-Type' => 'force-download',
    'Content-Disposition' => 'attachment; filename="' . $file->filename . '"',
    'Content-Length' => $file->filesize,
    'Content-Transfer-Encoding' => 'binary',
    'Pragma' => 'no-cache',
    'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
    'Expires' => '0',
    'Accept-Ranges' => 'bytes',
  );
  $headers = array_merge($default_headers, $headers);
  file_transfer($file->uri, $headers);
}