Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Add the File::sendToBrowser() method (see #4696)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Feb 15, 2013
1 parent 954c718 commit 4cdadbe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
13 changes: 1 addition & 12 deletions contao/library/Contao/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1959,18 +1959,7 @@ public static function sendFileToBrowser($strFile)
session_write_close();

// Open the "save as …" dialogue
header('Content-Type: ' . $objFile->mime);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $objFile->basename . '"');
header('Content-Length: ' . $objFile->filesize);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Expires: 0');
header('Connection: close');

$resFile = fopen(TL_ROOT . '/' . $strFile, 'rb');
fpassthru($resFile);
fclose($resFile);
$objFile->sendToBrowser();

// HOOK: post download callback
if (isset($GLOBALS['TL_HOOKS']['postDownload']) && is_array($GLOBALS['TL_HOOKS']['postDownload']))
Expand Down
20 changes: 20 additions & 0 deletions contao/library/Contao/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,26 @@ public function copyTo($strNewName)
}


/**
* Send the file to the browser
*/
public function sendToBrowser()
{
header('Content-Type: ' . $this->mime);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $this->basename . '"');
header('Content-Length: ' . $this->filesize);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Expires: 0');
header('Connection: close');

$resFile = fopen(TL_ROOT . '/' . $this->strFile, 'rb');
fpassthru($resFile);
fclose($resFile);
}


/**
* Write data to a file
*
Expand Down

0 comments on commit 4cdadbe

Please sign in to comment.