View Single Post
Old 05-13-2003, 05:24 PM  
sneaker
So Fucking Banned
 
Join Date: Dec 2002
Posts: 251
Here is an awesome script function that I use to send files to the browser, it controls the memory buffer and also kills the script in the event the user cancels that way your CPU/PHP processes are not running till completed on 50mb files, if you need any php/mysql programming done please let me know I am for hire. Also I didn't leave out or miss anything when coping the code because I left out some stuff that I use to check that the user has access. I also cleaned it up a little bit to be more simplified any php programmer should be able to see what the code below was intended to do, so without further babble here it is:


send_file($path,$fileid) {
// Sets Variables

$status = FALSE;
$name = "asianxxx_" . "$fileid" . ".zip";

// Returns false if connection ends or path is invalid

if (!is_file($path) or connection_status()!=0) return(FALSE);

// Set the Headers

header("Content-type: application/octet-stream");
header("Content-Disposition: inline; filename=\"".$name."\"");
header("Content-length: ".(string)(filesize($path)));
header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

// Send the file with an 8k Memory Buffer and still connected

if ($file = fopen($path, 'rb')) {
while(!feof($file) and (connection_status()hahahaha0)) {
print(fread($file, 1024*8));
flush();
}
$status = (connection_status()hahahaha0);
fclose($file);
}
return($status);
}

// Here is the routine I use to call the function above...

if (!send_file($path,$itemid)) {
// Runs the below commands if the download failed

} else {
// Runs the below commands if the download was successful


}
sneaker is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote