So ive got a streaming file down-loader script.
Basically we allow our clients to click a link which streams a generically named file (normally an ID to a resource record we have) and we stream it when the proper filename so they can download it.
FIle download works without a kink. However sometimes we glitch the system somehow and it does this.
Seems like it tries to stream the file on the next page load basically streaming the first part of the html and breaking the next page.
Heres the code we use to stream the downloads
So my question is does anyone have a clue in whats causing this to happen.
Basically we allow our clients to click a link which streams a generically named file (normally an ID to a resource record we have) and we stream it when the proper filename so they can download it.
FIle download works without a kink. However sometimes we glitch the system somehow and it does this.
Seems like it tries to stream the file on the next page load basically streaming the first part of the html and breaking the next page.
Heres the code we use to stream the downloads
Code:
public function send_file($path, $file_name="", $vars=array()) {
session_write_close();
@ob_end_clean();
if (!is_file($path) || connection_status()!=0) {
return(FALSE);
}
// PREVENT LONG FILES GETTING CUT OFF FROM max_execution_time
set_time_limit(0);
// GET BASENAME
if(empty($file_name)) {
$file_name=basename($path);
}
if(!isset($vars["force"])) {
$vars["force"]=1;
}
// DECODE HTML ENTITES
$file_name = html_entity_decode($file_name, ENT_QUOTES);
// STRIP CHARS
require_once($GLOBALS["SCRIPT_CLASS_DIR"]."functions.class.inc");
$functions = new functions;
$file_name = $functions->strip_chars_filename($file_name);
unset($functions);
// FILENAMES IN IE CONTAINING DOTS WILL SCREW UP THE FILENAME, SO STRIP
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {
$file_name = preg_replace("/\./", "%2e", $file_name, substr_count($file_name, ".") - 1);
}
////////////////////
// REQUIRED HEADERS
////////////////////
// IF SSL
if(!empty($_SERVER["HTTPS"])) {
// HEADERS IE REQUIRES FOR HTTPS
header("Cache-Control: private");
header("Pragma: private");
} else {
//header("Cache-Control: no-cache, must-revalidate");
header("Pragma: public");
}
header("Expires: 0");
header("Content-Length: ".@filesize($path));
header("Content-Type: application/octet-stream");
header('Content-Disposition: inline; filename="'.$file_name.'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path);
return((connection_status()==0) and !connection_aborted());
}
So my question is does anyone have a clue in whats causing this to happen.
Last edited: