Thanks for all your help. The script is working. I suppose I will post the finished file upload script here for the next guy who needs a working download script. You will have to change some headers if you are not downloading a zip file or if you want to allow the download of multiple zip files. I found that when using fpassthru the maximum php memory limit in php.ini pertains to a particular instance of a script running. Each time the script runs it appears that it will use up to the maximum memory limit. The configuration variables that need to be changed in the php.ini file to allow large files to be downloaded are.
memory_limit = 16M ; Maximum amount of memory a script may consume (8MB)
; Maximum size of POST data that PHP will accept.
post_max_size = 16M
<?php
// This script queries a database and downloads a zip file
// written by Greg Tibbetts 10/13/2006 greg@aagthosting.com
ob_start();
session_start();
// Protect against reaching max execution time
set_time_limit(0);
// Force script termination if user aborts
ignore_user_abort(false);
include '../include/db.inc';
include '../include/error.inc';
include '../include/include.inc';
include '../include/generalQuery.inc';
//include '../include/databaseUpdates.inc';
set_error_handler("errorHandler");
if (isset($_SESSION['targetLogin'])){
// write and close the session
session_write_close();
// Open a connection to the DBMS
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();
if (!mysql_select_db($databaseName, $connection))
showerror();
// query the download table
generalQuery($connection, "downloads");
// get the results of the query from the session and unset the session
$result = $_SESSION['result'];
unset($_SESSION['result']);
// fetch the row
$row = @ mysql_fetch_assoc($result);
$fileDir = $row['file_path']; // supply a path name.
$fileName = $row['file_name']; // supply a file name.
$fileString = $fileDir . '/' . $fileName; // combine the path and file
// translate file name properly for Internet Explorer.
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){
$fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
}
// make sure the file exists before sending headers
if(!$fdl = @fopen($fileString,'r')){
die("Cannot Open File!");
}
else {
//Close the session to allow for header() to be sent
header('Pragma: ');// leave blank to avoid IE errors
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Description: File Transfer');
header('Content-type: application/zip');
header('Content-Transfer-Encoding: binary');
$header="Content-Disposition: attachment; filename=" . $fileName . ";";
header($header);
header('Content-length:' . (string)(filesize($fileString)));
sleep(1);
fpassthru($fdl);
// increment the download counter
//databaseUpdates(&$connection, "downloads");
}
}
ob_end_flush();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Video Download</title>
</head>
<body>
</body>
</html>
Heres showerror();
// The error.inc
// Trigger an error condition
function showerror(){
if (mysql_errno() || mysql_error())
trigger_error("MySQL error: " .
mysql_errno() .
" : " . mysql_error(),
E_USER_ERROR);
else
trigger_error("Could not connect to DBMS",
E_USER_ERROR);
}