[ Index ] |
PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved. 6 7 This script is part of PHPWCMS. The PHPWCMS web content management system is 8 free software; you can redistribute it and/or modify it under the terms of 9 the GNU General Public License as published by the Free Software Foundation; 10 either version 2 of the License, or (at your option) any later version. 11 12 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 13 A copy is found in the textfile GPL.txt and important notices to the license 14 from the author is found in LICENSE.txt distributed with these scripts. 15 16 This script is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 18 PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 20 This copyright notice MUST APPEAR in all copies of the script! 21 *************************************************************************************/ 22 23 24 function _getFileInfo($value, $limit='1', $mode='hash') { 25 26 $sql = ''; 27 28 switch($mode) { 29 30 case 'hash': $sql = "SELECT * FROM ".DB_PREPEND."phpwcms_file WHERE f_aktiv=1 AND "; 31 $sql .= "f_trash=0 AND f_public=1 AND "; 32 $sql .= "f_hash='".aporeplace($value)."'"; 33 if( !FEUSER_LOGIN_STATUS ) { 34 $sql .= ' AND f_granted=0'; 35 } 36 if($limit) { 37 $sql .= " LIMIT ".$limit; 38 } 39 break; 40 } 41 42 return _dbQuery($sql); 43 44 } 45 46 function dl_file_resume($file='', $fileinfo=array(), $onsuccess = false) { 47 48 // function based on this one here: 49 // http://www.php.net/manual/de/function.fread.php#63893 50 51 //First, see if the file exists 52 if (!is_file($file) && connection_status()) return false; 53 54 //Gather relevent info about file 55 $filename = empty($fileinfo['realfname']) ? basename($file) : $fileinfo['realfname']; 56 $disposition = empty($fileinfo['method']) ? 'attachment' : $fileinfo['method']; 57 58 if($disposition == 'attachment') { 59 60 $fileinfo['mimetype'] = "application/force-download"; 61 62 } 63 64 if(empty($fileinfo['mimetype']) && empty($fileinfo['extension'])) { 65 66 $file_extension = strtolower(substr(strrchr($filename,"."),1)); 67 68 //This will set the Content-Type to the appropriate setting for the file 69 switch( $file_extension ) { 70 case "exe": $ctype="application/octet-stream"; break; 71 case "zip": $ctype="application/zip"; break; 72 case "mp3": $ctype="audio/mpeg"; break; 73 case "mpg": $ctype="video/mpeg"; break; 74 case "avi": $ctype="video/x-msvideo"; break; 75 default: $ctype="application/force-download"; 76 } 77 78 } else { 79 80 $ctype = $fileinfo['mimetype']; 81 $file_extension = $fileinfo['extension']; 82 83 } 84 85 //Begin writing headers 86 header('Cache-Control: '); 87 header('Cache-Control: public'); 88 header('Pragma: '); 89 90 //Use the switch-generated Content-Type 91 header('Content-Type: '.$ctype); 92 93 94 if (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { 95 // workaround for IE filename bug with multiple periods / multiple dots in filename 96 // that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe 97 $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1); 98 } 99 100 101 //header('Accept-Ranges: bytes'); 102 103 $size = filesize($file); 104 105 106 header('Content-Length: '.$size); 107 header('Content-Transfer-Encoding: binary'.LF); 108 109 110 //check if http_range is sent by browser (or download manager) 111 /* 112 if(isset($_SERVER['HTTP_RANGE'])) { 113 114 //if yes, download missing part 115 list($a, $range) = explode('=', $_SERVER['HTTP_RANGE']); 116 $range = explode('-', $range); 117 $seek_start = empty($range[0]) ? 0 : intval($range[0]); 118 $seek_end = empty($range[1]) ? 0 : intval($range[1]); 119 120 header('HTTP/1.1 206 Partial Content'); 121 header('Content-Length: '.($seek_end - $seek_start + 1)); 122 header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$size); 123 124 } else { 125 126 $rage = 0; 127 header('Content-Range: bytes 0-'. ($size - 1) .'/'.$size); 128 header('Content-Length: '.$size); 129 130 } 131 */ 132 133 header('Content-Disposition: '.$disposition.'; filename="'.$filename.'"'); 134 135 136 //reset time limit for big files 137 @set_time_limit(0); 138 139 //open the file 140 $fp = fopen($file, 'rb'); 141 142 //seek to start of missing part 143 //fseek($fp, $range); 144 145 //start buffered download 146 while(!feof($fp) && !connection_status()){ 147 148 print(fread($fp, 1024*8)); 149 flush(); 150 //ob_flush(); 151 } 152 fclose($fp); 153 154 return ($onsuccess && !connection_status() && !connection_aborted()) ? true : false; 155 } 156 157 158 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 30 05:55:15 2009 | Cross-referenced by PHPXref 0.7 |