Download.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Group                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: Jason Rust <jrust@codejanitor.com>                          |
00020 // +----------------------------------------------------------------------+
00021 
00022 // }}}
00023 // {{{ requires
00024 
00025 require_once dirname(__FILE__) . '/../Action.php';
00026 require_once dirname(__FILE__) . '/../FileCache.php';
00027 
00028 // }}}
00029 // {{{ class FF_Action_Download 
00030 
00041 // }}}
00042 class FF_Action_Download extends FF_Action {
00043     // {{{ run()
00044     
00051     function run()
00052     {
00053         $o_fileCache =& FF_FileCache::singleton();
00054         $a_parts = array();
00055         if (FF_Request::getParam('path', 'g', false)) {
00056             $a_parts['subdir'] = FF_Request::getParam('path', 'g');
00057         }
00058 
00059         if (FF_Request::getParam('id', 'g', false)) {
00060             $a_parts['id'] = FF_Request::getParam('id', 'g');
00061         }
00062 
00063         $a_parts['name'] = FF_Request::getParam('name', 'g');
00064 
00065         if (!$o_fileCache->exists($a_parts, FF_Request::getParam('useApp', 'g', false))) {
00066             $this->o_output->setMessage(_('The specified file could not be found.'), FASTFRAME_ERROR_MESSAGE, true);
00067             $this->o_nextAction->setActionId(ACTION_PROBLEM);
00068             return $this->o_nextAction;
00069         }
00070 
00071         $s_file = $o_fileCache->getPath($a_parts, FF_Request::getParam('useApp', 'g', false));
00072 
00073         header('Pragma: public');
00074         header('Expires: 0');
00075         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
00076         if (!FF_Request::getParam('displayFile', 'g', false)) {
00077             header('Content-Type: application/force-download');
00078             header('Content-Disposition: attachment; filename="' . $a_parts['name'] . '"');
00079             header('Content-Description: File Transfer');
00080         }
00081         else {
00082             header('Content-Type: ' . $o_fileCache->getContentType($a_parts['name']));
00083         }
00084 
00085         header('Accept-Ranges: bytes');
00086         header('Content-Length: ' . filesize($s_file));
00087         @readfile($s_file);
00088         exit;
00089     }
00090 
00091     // }}}
00092 }
00093 ?>

Generated on Fri Jun 23 11:38:15 2006 for FastFrame by  doxygen 1.4.4