root/wifidog/wifidog-auth/wifidog/file_download.php
| Revision 395, 4.4 kB (checked in by syrus, 1 year ago) |
|---|
| Line | |
|---|---|
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
| 5 | |
| 6 | // +-------------------------------------------------------------------+ |
| 7 | // | WiFiDog Authentication Server | |
| 8 | // | ============================= | |
| 9 | // | | |
| 10 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
| 11 | // | portal suite. | |
| 12 | // +-------------------------------------------------------------------+ |
| 13 | // | PHP version 5 required. | |
| 14 | // +-------------------------------------------------------------------+ |
| 15 | // | Homepage: http://www.wifidog.org/ | |
| 16 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
| 17 | // +-------------------------------------------------------------------+ |
| 18 | // | This program is free software; you can redistribute it and/or | |
| 19 | // | modify it under the terms of the GNU General Public License as | |
| 20 | // | published by the Free Software Foundation; either version 2 of | |
| 21 | // | the License, or (at your option) any later version. | |
| 22 | // | | |
| 23 | // | This program is distributed in the hope that it will be useful, | |
| 24 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 26 | // | GNU General Public License for more details. | |
| 27 | // | | |
| 28 | // | You should have received a copy of the GNU General Public License | |
| 29 | // | along with this program; if not, contact: | |
| 30 | // | | |
| 31 | // | Free Software Foundation Voice: +1-617-542-5942 | |
| 32 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
| 33 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
| 34 | // | | |
| 35 | // +-------------------------------------------------------------------+ |
| 36 | |
| 37 | /** |
| 38 | * @package WiFiDogAuthServer |
| 39 | * @author Francois Proulx <francois.proulx@gmail.com> |
| 40 | * @copyright 2005-2006 Francois Proulx, Technologies Coeus inc. |
| 41 | * @version Subversion $Id: file_download.php 1074 2006-06-18 09:53:56Z fproulx $ |
| 42 | * @link http://www.wifidog.org/ |
| 43 | */ |
| 44 | |
| 45 | /** |
| 46 | * Load required files |
| 47 | */ |
| 48 | require_once (dirname(__FILE__) . '/include/common.php'); |
| 49 | |
| 50 | if (!empty ($_REQUEST['file_id'])) |
| 51 | { |
| 52 | global $db; |
| 53 | $file_id = $db->escapeString($_REQUEST['file_id']); |
| 54 | $sql = "SELECT * FROM content_file WHERE files_id = '$file_id'"; |
| 55 | $db->execSqlUniqueRes($sql, $file_row, false); |
| 56 | |
| 57 | if ($file_row && $file_row['data_blob']) |
| 58 | { |
| 59 | // Check if the HTTP request is asking if the file has been modified since a certain date. |
| 60 | $last_modified_date = isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : 0; |
| 61 | if($last_modified_date && $_SERVER['REQUEST_METHOD'] == "GET" && strtotime($last_modified_date) >= strtotime($file_row['last_update_date'])) |
| 62 | header("HTTP/1.1 304 Not Modified"); |
| 63 | else |
| 64 | { |
| 65 | //headers to send to the browser before beginning the binary download |
| 66 | header("Pragma: public"); |
| 67 | // Send last update date to proxy / cache the binary |
| 68 | header("Last-Modified: " . gmdate("D, d M Y H:i:s", strtotime($file_row['last_update_date'])) . " GMT"); |
| 69 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
| 70 | header("Cache-Control: public"); |
| 71 | header("Content-Description: File Transfer"); |
| 72 | header('Content-Type: ' . $file_row['mime_type']); |
| 73 | header("Content-Transfer-Encoding: binary"); |
| 74 | header('Accept-Ranges: bytes'); |
| 75 | if (strpos($file_row['mime_type'], "image") === false) |
| 76 | header('Content-Length: ' .$file_row['local_binary_size']); //this is the size of the zipped file |
| 77 | header('Keep-Alive: timeout=15, max=100'); |
| 78 | header('Content-Disposition: inline; filename="' . $file_row['filename'] . '"'); |
| 79 | |
| 80 | // Do not send binary if this is only a HEAD request |
| 81 | if ($_SERVER["REQUEST_METHOD"] != "HEAD") |
| 82 | $db->readFlushLargeObject($file_row['data_blob']); |
| 83 | } |
| 84 | } |
| 85 | else |
| 86 | header("HTTP/1.1 404 Not Found"); |
| 87 | } |
| 88 | else |
| 89 | header("HTTP/1.1 404 Not Found"); |
| 90 | |
| 91 | /* |
| 92 | * Local variables: |
| 93 | * tab-width: 4 |
| 94 | * c-basic-offset: 4 |
| 95 | * c-hanging-comment-ender-p: nil |
| 96 | * End: |
| 97 | */ |
| 98 | ?> |
Note: See TracBrowser for help on using the browser.
