function mime_default_download(&$pFileHash) { global $gBitSystem; $ret = FALSE; // Check to see if the file actually exists if (!empty($pFileHash['source_file']) && is_readable($pFileHash['source_file'])) { // if we have PEAR HTTP/Download installed, we make use of it since it allows download resume and download manager access // read the docs if you want to enable download throttling and the like if (@(include_once 'HTTP/Download.php')) { $dl = new HTTP_Download(); $dl->setLastModified($pFileHash['last_modified']); $dl->setFile($pFileHash['source_file']); //$dl->setContentDisposition( HTTP_DOWNLOAD_INLINE, $pFileHash['file_name'] ); $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $pFileHash['file_name']); $dl->setContentType($pFileHash['mime_type']); $res = $dl->send(); if (PEAR::isError($res)) { $gBitSystem->fatalError($res->getMessage()); } else { $ret = TRUE; } } else { // make sure we close off obzip compression if it's on if ($gBitSystem->isFeatureActive('site_output_obzip')) { @ob_end_clean(); } // this will get the browser to open the download dialogue - even when the // browser could deal with the content type - not perfect, but works if ($gBitSystem->isFeatureActive('mime_force_download')) { $pFileHash['mime_type'] = "application/force-download"; } header("Cache Control: "); header("Accept-Ranges: bytes"); header("Content-type: " . $pFileHash['mime_type']); header("Content-Disposition: attachment; filename=" . $pFileHash['file_name']); header("Last-Modified: " . gmdate("D, d M Y H:i:s", $pFileHash['last_modified']) . " GMT", true, 200); header("Content-Length: " . filesize($pFileHash['source_file'])); header("Content-Transfer-Encoding: binary"); header("Connection: close"); readfile($pFileHash['source_file']); $ret = TRUE; die; } } else { $pFileHash['errors']['no_file'] = tra('No matching file found.'); } return $ret; }
<?php // Check to see if the file actually exists if (is_readable($fileHash['source_file'])) { // if we have PEAR HTTP/Download installed, we make use of it since it allows download resume and download manager access // read the docs if you want to enable download throttling and the like if (@(include_once 'HTTP/Download.php')) { $dl = new HTTP_Download(); $dl->setLastModified($fileHash['last_modified']); $dl->setFile($fileHash['source_file']); $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $fileHash['filename']); $dl->setContentType($fileHash['mime_type']); $res = $dl->send(); if (PEAR::isError($res)) { $gBitSystem->fatalError($res->getMessage()); } } else { header("Cache Control: "); header("Accept-Ranges: bytes"); header("Content-type: " . $fileHash['mime_type']); header("Content-Disposition: attachment; filename=" . $fileHash['filename']); header("Last-Modified: " . gmdate("D, d M Y H:i:s", $fileHash['last_modified']) . " GMT", true, 200); header("Content-Length: " . filesize($fileHash['source_file'])); header("Content-Transfer-Encoding: binary"); header("Connection: close"); readfile($fileHash['source_file']); } }