| 1 |
|
<?php |
| 2 |
|
/** |
| 3 |
|
* Xyster Framework |
| 4 |
|
* |
| 5 |
|
* LICENSE |
| 6 |
|
* |
| 7 |
|
* This source file is subject to the new BSD license that is bundled |
| 8 |
|
* with this package in the file LICENSE.txt. |
| 9 |
|
* It is also available through the world-wide-web at this URL: |
| 10 |
|
* http://www.opensource.org/licenses/bsd-license.php |
| 11 |
|
* If you did not receive a copy of the license and are unable to |
| 12 |
|
* obtain it through the world-wide-web, please send an email |
| 13 |
|
* to xyster@devweblog.org so we can send you a copy immediately. |
| 14 |
|
* |
| 15 |
|
* @category Xyster |
| 16 |
|
* @package Xyster_Controller |
| 17 |
|
* @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org) |
| 18 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 19 |
|
* @version $Id: File.php 92 2007-09-19 01:16:26Z doublecompile $ |
| 20 |
|
*/ |
| 21 |
|
/** |
| 22 |
|
* Zend_Controller_Action_Helper_Abstract |
| 23 |
|
*/ |
| 24 |
1 |
require_once 'Zend/Controller/Action/Helper/Abstract.php'; |
| 25 |
|
/** |
| 26 |
|
* File response headers action helper |
| 27 |
|
* |
| 28 |
|
* @category Xyster |
| 29 |
|
* @package Xyster_Controller |
| 30 |
|
* @subpackage Helpers |
| 31 |
|
* @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org) |
| 32 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 33 |
|
*/ |
| 34 |
|
class Xyster_Controller_Action_Helper_File extends Zend_Controller_Action_Helper_Abstract |
| 35 |
|
{ |
| 36 |
|
/** |
| 37 |
|
* The default MIME type |
| 38 |
|
* |
| 39 |
|
*/ |
| 40 |
|
const DEFAULT_MIME = 'application/octet-stream'; |
| 41 |
|
|
| 42 |
|
/** |
| 43 |
|
* Sets the appropriate headers for sending a file as a response |
| 44 |
|
* |
| 45 |
|
* This helper uses {@link Xyster_Controller_Action_Helper_Cache} to check |
| 46 |
|
* if the file has been modified since the user last received it. |
| 47 |
|
* |
| 48 |
|
* @param string $name The filename |
| 49 |
|
* @param string $mime The MIME type of the file |
| 50 |
|
* @param int $date The unix timestamp the file was last modified |
| 51 |
|
*/ |
| 52 |
|
public function direct( $name, $mime = self::DEFAULT_MIME, $date = null ) |
| 53 |
|
{ |
| 54 |
2 |
$this->setFileHeaders($name, $mime, $date); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
/** |
| 58 |
|
* Sets the appropriate headers for sending a file as a response |
| 59 |
|
* |
| 60 |
|
* This helper uses {@link Xyster_Controller_Action_Helper_Cache} to check |
| 61 |
|
* if the file has been modified since the user last received it. |
| 62 |
|
* |
| 63 |
|
* @param string $name The filename |
| 64 |
|
* @param string $mime The MIME type of the file |
| 65 |
|
* @param int $date The unix timestamp the file was last modified |
| 66 |
|
*/ |
| 67 |
|
public function setFileHeaders( $name, $mime = self::DEFAULT_MIME, $date = null ) |
| 68 |
|
{ |
| 69 |
2 |
if ( $this->getActionController()->getHelper('Cache')->direct($date) ) { |
| 70 |
1 |
return; |
| 71 |
0 |
} |
| 72 |
|
|
| 73 |
1 |
if ( !headers_sent() ) { |
| 74 |
0 |
ini_set('zlib.output_compression', 'Off'); |
| 75 |
0 |
} |
| 76 |
|
|
| 77 |
1 |
$this->getResponse() |
| 78 |
1 |
->setHeader('Accept-Ranges', 'bytes') |
| 79 |
1 |
->setHeader('Content-Type', $mime) |
| 80 |
1 |
->setHeader('Content-Disposition', 'attachment; filename=' . $name); |
| 81 |
|
} |
| 82 |
|
} |