mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE: Deprecated HTTP::sendFileToBrowser() in favour of more testable HTTPRequest::send_file()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63579 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
fbd37c897e
commit
25157f7cf9
@ -133,27 +133,9 @@ class HTTP {
|
||||
* exits() after the call, so that no further output is given
|
||||
*/
|
||||
static function sendFileToBrowser($fileData, $fileName, $mimeType = false) {
|
||||
if(!$mimeType) $mimeType = self::getMimeType($fileName);
|
||||
$ext = strtolower(substr($fileName,strrpos($fileName,'.')+1));
|
||||
$inlineExtensions = array('pdf','png','jpg','jpe','gif','swf','htm','html','txt','text','avi','wmv','mov','mpe','mpg','mp3','mpeg');
|
||||
|
||||
if(in_array($ext, $inlineExtensions)) $inline = true;
|
||||
|
||||
header("Content-Type: $mimeType; name=\"" . addslashes($fileName) . "\"");
|
||||
//header("Content-Type: $mimeType" );
|
||||
// Downloadable
|
||||
//if(!$inline)
|
||||
$dispHeader = "Content-disposition: attachment; filename=" . addslashes($fileName) . "";
|
||||
|
||||
// Debug::message('CD: ' . strlen( $dispHeader ) );
|
||||
|
||||
|
||||
header( $dispHeader );
|
||||
header("Content-Length: " . strlen($fileData));
|
||||
|
||||
echo $fileData;
|
||||
|
||||
exit();
|
||||
user_error("HTTP::sendFileToBrowser() deprecated; return a HTTPResponse::send_file() object instead", E_USER_NOTICE);
|
||||
HTTPRequest::send_file($fileData, $fileName, $mimeType)->output();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -196,6 +196,20 @@ class HTTPRequest extends Object implements ArrayAccess {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an HTTPResponse that will deliver a file to the client
|
||||
*/
|
||||
static function send_file($fileData, $fileName, $mimeType = null) {
|
||||
if(!$mimeType) $mimeType = HTTP::getMimeType($fileName);
|
||||
|
||||
$response = new HTTPResponse($fileData);
|
||||
$response->addHeader("Content-Type", "$mimeType; name=\"" . addslashes($fileName) . "\"");
|
||||
$response->addHeader("Content-disposition", "attachment; filename=" . addslashes($fileName));
|
||||
$response->addHeader("Content-Length", strlen($fileData));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a URL pattern
|
||||
* The pattern can contain a number of segments, separted by / (and an extension indicated by a .)
|
||||
|
Loading…
Reference in New Issue
Block a user