Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

(Fixes issue 3154) xSendFile - removed file existance check and added…

… additional headers option
  • Loading branch information...
commit 04aa9a56b7bd8326ce20469fb1ef3adf5441c1e1 1 parent 5398fff
mdomba authored
Showing with 19 additions and 15 deletions.
  1. +1 −0  CHANGELOG
  2. +3 −1 UPGRADE
  3. +15 −14 framework/web/CHttpRequest.php
View
1  CHANGELOG
@@ -16,6 +16,7 @@ Version 1.1.10 work in progress
- Enh #3101: The methods of CSecurityManager do now work correctly for the case that mbstring.func_overload is in effect (Y!!)
- Enh #3112: Fixed the exception error display on ajax calls when YII_DEBUG is true (mdomba)
- Enh #3121: Added more rules for proper pluralization to the pluralize() method in CCodeModel and CConsoleCommand (mdomba)
+- Enh #3154: Removed file existance check to allow relative path and added additional headers option to xSendFile() (mdomba)
- Enh #3169: Added CSort::SORT_ASC and CSort::SORT_DESC (Sam Dark)
- Enh: Added CActiveForm::validateTabular() to simplify ajax validation for tabular input (mdomba)
- Chg: HTML-encoded input values for exist and unique validators (Qiang)
View
4 UPGRADE
@@ -21,7 +21,9 @@ General upgrade intructions
Upgrading from v1.1.9
---------------------
-
+- Previously xSendFile() was returning false if the file was not found.
+This has been removed to allow relative file paths. If you are relying on this check,
+you will need to do it manually before calling xSendFile().
Upgrading from v1.1.8
---------------------
View
29 framework/web/CHttpRequest.php
@@ -811,29 +811,26 @@ public function sendFile($fileName,$content,$mimeType=null,$terminate=true)
* <b>Example</b>:
* <pre>
* <?php
- * Yii::app()->request->xSendFile('/home/user/Pictures/picture1.jpg',array(
- * 'saveName'=>'image1.jpg',
- * 'mimeType'=>'image/jpeg',
- * 'terminate'=>false,
- * ));
+ * Yii::app()->request->xSendFile('/home/user/Pictures/picture1.jpg',array(
+ * 'saveName'=>'image1.jpg',
+ * 'mimeType'=>'image/jpeg',
+ * 'terminate'=>false,
+ * ));
* ?>
* </pre>
* @param string $filePath file name with full path
* @param array $options additional options:
* <ul>
* <li>saveName: file name shown to the user, if not set real file name will be used</li>
- * <li>mimeType: mime type of the file, if not set it will be guessed automatically based on the file name.</li>
+ * <li>mimeType: mime type of the file, if not set it will be guessed automatically based on the file name, if set to null no content-type header will be sent.</li>
* <li>xHeader: appropriate x-sendfile header, defaults to "X-Sendfile"</li>
* <li>terminate: whether to terminate the current application after calling this method, defaults to true</li>
- * <li>forceDownload: specifies whether the file will be downloaded or shown inline. Defaults to true. (Since version 1.1.9.)</li>
+ * <li>forceDownload: specifies whether the file will be downloaded or shown inline, defaults to true. (Since version 1.1.9.)</li>
+ * <li>addHeaders: an array of additional http headers in header-value pairs</li>
* </ul>
- * @return boolean false if file not found, true otherwise.
*/
public function xSendFile($filePath, $options=array())
{
- if(!is_file($filePath))
- return false;
-
if(!isset($options['forceDownload']) || $options['forceDownload'])
$disposition='attachment';
else
@@ -851,14 +848,18 @@ public function xSendFile($filePath, $options=array())
if(!isset($options['xHeader']))
$options['xHeader']='X-Sendfile';
- header('Content-type: '.$options['mimeType']);
+ if($options['mimeType'] !== null)
+ header('Content-type: '.$options['mimeType']);
header('Content-Disposition: '.$disposition.'; filename="'.$options['saveName'].'"');
+ if(isset($options['addHeaders']))
+ {
+ foreach($options['addHeaders'] as $header=>$value)
+ header($header.': '.$value);
+ }
header(trim($options['xHeader']).': '.$filePath);
if(!isset($options['terminate']) || $options['terminate'])
Yii::app()->end();
-
- return true;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.