summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY1
-rw-r--r--framework/Web/THttpResponse.php35
2 files changed, 22 insertions, 14 deletions
diff --git a/HISTORY b/HISTORY
index 0e5fc14c..22d85ad7 100644
--- a/HISTORY
+++ b/HISTORY
@@ -6,6 +6,7 @@ BUG: Non-control components can now use expressions in their properties (Qiang)
BUG: TControl.Visible did not make use of overriden getVisible() (Qiang)
BUG: TWizard did not stop navigation upon a validation failure (Qiang)
ENH: TButton, TImageButton and TLinkButton now implement IButtonControl interface (Qiang)
+ENH: TResponse::writeFile takes two additional parameters to allow sending memory data (Qiang)
Version 3.0RC2 April 16, 2006
=============================
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index 3d297e0a..ee2dd99b 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -220,9 +220,11 @@ class THttpResponse extends TModule implements ITextWriter
* Sends a file back to user.
* Make sure not to output anything else after calling this method.
* @param string file name
+ * @param string content to be set. If null, the content will be read from the server file pointed to by $fileName.
+ * @param string mime type of the content.
* @throws TInvalidDataValueException if the file cannot be found
*/
- public function writeFile($fileName)
+ public function writeFile($fileName,$content=null,$mimeType=null)
{
static $defaultMimeTypes=array(
'css'=>'text/css',
@@ -234,26 +236,31 @@ class THttpResponse extends TModule implements ITextWriter
'js'=>'javascript/js'
);
- if(!is_file($fileName))
- throw new TInvalidDataValueException('httpresponse_file_inexistent',$fileName);
- header('Pragma: public');
- header('Expires: 0');
- header('Cache-Component: must-revalidate, post-check=0, pre-check=0');
- $mimeType='text/plain';
- if(function_exists('mime_content_type'))
- $mimeType=mime_content_type($fileName);
- else
+ if($mimeType===null)
{
- $ext=array_pop(explode('.',$fileName));
- if(isset($defaultMimeTypes[$ext]))
- $mimeType=$defaultMimeTypes[$ext];
+ if(function_exists('mime_content_type'))
+ $mimeType=mime_content_type($fileName);
+ else
+ {
+ $ext=array_pop(explode('.',$fileName));
+ if(isset($defaultMimeTypes[$ext]))
+ $mimeType=$defaultMimeTypes[$ext];
+ else
+ $mimeType='text/plain';
+ }
}
$fn=basename($fileName);
+ header('Pragma: public');
+ header('Expires: 0');
+ header('Cache-Component: must-revalidate, post-check=0, pre-check=0');
header("Content-type: $mimeType");
header('Content-Length: '.filesize($fileName));
header("Content-Disposition: attachment; filename=\"$fn\"");
header('Content-Transfer-Encoding: binary');
- readfile($fileName);
+ if($content===null)
+ readfile($fileName);
+ else
+ echo $content;
}
/**