XeonGX
New Member
Hello,
Today I just discovered that my download script times out. :cry2:
When download reaches 39.9MB it stops,
Can somebody help fix the code?
download.php
dl.php
Today I just discovered that my download script times out. :cry2:
When download reaches 39.9MB it stops,
Can somebody help fix the code?
download.php
PHP:
<?
include ( "member/db.php" );
include ( "member/settings.php" );
include ( "member/header.php" );
if ( !isset ( $user_info[user_id] ) ) {
header( "Location: $site_path/login" );
exit();
ob_end_flush();
}
###############################################################
# Above part only allows members to execute the script.
###############################################################
?>
<?
session_start( );
if( !$_SESSION['DownloadCount'] and !$_COOKIE['DownloadCount'] ) $_SESSION['DownloadCount'] = 1;
$dl_limit = "5"; # 5
$dl_period = "3600"; # per 1 hour
setcookie("DownloadCount", $_SESSION['DownloadCount'] );
$_SESSION['DownloadCount']++;
if( $_COOKIE['DownloadCount'] < $dl_limit )
include "dl.php";
else
echo "<script language=\"javascript\">alert('You have reached or exceeded your download limit')</script>";
?>
dl.php
PHP:
<?php
###############################################################
# File Download 1.1
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
# Sample call:
# download.php?f=phptutorial.zip
#
# Sample call (browser will try to save with new file name):
# download.php?f=phptutorial.zip&fc=php123tutorial.zip
###############################################################
// Download folder, i.e. folder where you keep all files for download.
// MUST end with slash (i.e. "/" )
define('BASE_DIR','/home/joan/backup/');
// log downloads? true/false
define('LOG_DOWNLOADS',true);
// log file name
define('LOG_FILE','downloads.log');
// Allowed extensions list in format 'extension' => 'mime type'
// If myme type is set to empty string then script will try to detect mime type
// itself, which would only work if you have Mimetype or Fileinfo extensions
// installed on server.
####################################################################
### DO NOT CHANGE BELOW
####################################################################
// Make sure program execution doesn't time out
// Set maximum script execution time in seconds (0 means no limit)
set_time_limit(0);
if (!isset($_GET['f']) || empty($_GET['f'])) {
die("Please specify file name for download.");
}
// Get real file name.
// Remove any path info to avoid hacking by adding relative path, etc.
$fname = basename($_GET['f']);
// Check if the file exists
// Check in subfolders too
function find_file ($dirname, $fname, &$file_path) {
$dir = opendir($dirname);
while ($file = readdir($dir)) {
if (empty($file_path) && $file != '.' && $file != '..') {
if (is_dir($dirname.'/'.$file)) {
find_file($dirname.'/'.$file, $fname, $file_path);
}
else {
if (file_exists($dirname.'/'.$fname)) {
$file_path = $dirname.'/'.$fname;
return;
}
}
}
}
} // find_file
// get full file path (including subfolders)
$file_path = '';
find_file(BASE_DIR, $fname, $file_path);
if (!is_file($file_path)) {
die("File does not exist. Make sure you specified correct file name.");
}
// file size in bytes
$fsize = filesize($file_path);
// file extension
$fext = strtolower(substr(strrchr($fname,"."),1));
// check if allowed extension
// get mime type
// Browser will try to save file with this filename, regardless original filename.
// You can override it if needed.
if (!isset($_GET['fc']) || empty($_GET['fc'])) {
$asfname = $fname;
}
else {
$asfname = $_GET['fc'];
}
// set headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=\"$asfname\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);
// download
@readfile($file_path);
// log downloads
if (!LOG_DOWNLOADS) die();
$f = @fopen(LOG_FILE, 'a+');
if ($f) {
@fputs($f, date("m.d.Y g:ia")." ".$_SERVER['REMOTE_ADDR']." ".$fname."\n");
@fclose($f);
}
?>