static function DownloadFile($filename, $display_name, $ext = "") { // TODO: We need a much better piece of code for downloading files here // it will end up being used for large attachments etc so needs to work with big files! if ($ext == "") { $ext = pathinfo($display_name, PATHINFO_EXTENSION); } $ctype = FSS_Helper::datei_mime($ext); ob_end_clean(); while (ob_get_level() > 0) { ob_end_clean(); } ini_set('zlib.output_compression', 'Off'); ini_set('output_buffering', 'Off'); ini_set('output_handler', ''); if (function_exists("apache_setenv")) { apache_setenv('no-gzip', 1); } require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'bigfiletools.php'; $f = BigFileTools::fromPath($filename); $file_size = $f->getSize(); header("Pragma: no-cache"); header("Expires: -1"); header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0"); header("Content-Type: " . $ctype); header("Content-Disposition: attachment; filename=\"{$display_name}\""); //check if http_range is sent by browser (or download manager) if (isset($_SERVER['HTTP_RANGE'])) { list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2); if ($size_unit == 'bytes') { //multiple ranges could be specified at the same time, but for simplicity only serve the first range //http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt list($range, $extra_ranges) = explode(',', $range_orig, 2); } else { $range = ''; header('HTTP/1.1 416 Requested Range Not Satisfiable'); exit; } } else { $range = ''; } //figure out download piece from range (if set) if ($range && strpos($range, "-") !== false) { list($seek_start, $seek_end) = @explode('-', $range, 2); } else { $seek_start = 0; $seek_end = 0; } //set start and end based on range (if set), else set defaults //also check for invalid ranges. $seek_end = empty($seek_end) ? $file_size - 1 : min(abs(intval($seek_end)), $file_size - 1); $seek_start = empty($seek_start) || $seek_end < abs(intval($seek_start)) ? 0 : max(abs(intval($seek_start)), 0); //Only send partial content header if downloading a piece of the file (IE workaround) if ($seek_start > 0 || $seek_end < $file_size - 1) { header('HTTP/1.1 206 Partial Content'); header('Content-Range: bytes ' . $seek_start . '-' . $seek_end . '/' . $file_size); header('Content-Length: ' . ($seek_end - $seek_start + 1)); } else { header("Content-Length: {$file_size}"); } set_time_limit(0); $file = fopen($filename, "rb"); while (!feof($file)) { echo @fread($file, 1024 * 256); @ob_flush(); @flush(); if (connection_status() != 0) { @fclose($file); exit; } } @fclose($file); exit; }
function downloadFile() { $fileid = FSS_Input::getInt('fileid'); $db = JFactory::getDBO(); $query = 'SELECT * FROM #__fss_kb_attach WHERE id = "' . FSSJ3Helper::getEscaped($db, $fileid) . '"'; $db->setQuery($query); $row = $db->loadAssoc(); $filename = FSS_Helper::basename($row['filename']); $file_extension = strtolower(substr(strrchr($filename, "."), 1)); $ctype = FSS_Helper::datei_mime($file_extension); if (ob_get_level() > 0) { ob_end_clean(); } $file = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'kb' . DS . $row['diskfile']; if (!file_exists($file)) { $file = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . $row['diskfile']; } if (!file_exists($file)) { echo "File not found - " . $row['diskfile'] . "<br />"; echo "Paths Tested:<br />"; echo "<ul>"; echo "<li>" . JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'kb' . "</li>"; echo "<li>" . JPATH_SITE . DS . FSS_Settings::get('attach_location') . "</li>"; echo "</ul>"; return; } header("Cache-Control: public, must-revalidate"); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header("Pragma: no-cache"); header("Expires: 0"); header("Content-Description: File Transfer"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Content-Type: " . $ctype); //header("Content-Length: ".(string)$row['size']); header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Transfer-Encoding: binary\n"); //echo getcwd(). "<br>"; //echo $file; readfile($file); exit; }
function download() { $fileid = JRequest::getVar('fileid', 0, '', 'int'); $db = JFactory::getDBO(); $query = 'SELECT * FROM #__fss_kb_attach WHERE id = "' . FSSJ3Helper::getEscaped($db, $fileid) . '"'; $db->setQuery($query); $row = $db->loadAssoc(); $filename = FSS_Helper::basename($row['filename']); $file_extension = strtolower(substr(strrchr($filename, "."), 1)); $ctype = FSS_Helper::datei_mime($file_extension); while (ob_get_level() > 0) { ob_end_clean(); } header("Cache-Control: public, must-revalidate"); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header("Pragma: no-cache"); header("Expires: 0"); header("Content-Description: File Transfer"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Content-Type: " . $ctype); //header("Content-Length: ".(string)$row['size']); header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Transfer-Encoding: binary\n"); //echo getcwd(). "<br>"; $file = "../components/com_fss/files/" . $row['diskfile']; //echo $file; @readfile($file); exit; }