<?php
################################################## #########
# FS.Download
# Version: 1.0b
# Author: bAAGi
# Email:
baagi@faultysanity.com
# Company: Faulty Sanity
# Website:
http://www.faultysanity.com/
################################################## #########
# COPYRIGHT
# You are free to use and modify this script as long as
# this header section stays intact.
################################################## #########
if(isset($_GET['file']) && $_GET['act']=="download") fs_download($_GET['file']);
function fs_download($file) {
$mysqlserver = "localhost";
$mysqluser = "username";
$mysqlpass = "password";
$mysqldbname = "database";
$serverPath = "/home/mysite/www/coding_stuff/downloads/";
$urlPath = "http://www.faultysanity.com/coding_stuff/downloads/";
# Set the date format. Check:
#
http://www.php.net/manual/en/function.date.php
# for help.
$dateFormat = "F j, Y";
#####
if(ereg("(\.zip|\.exe)$",$file)) {
$file = basename($file);
$pathtofile = $serverPath.$file;
if(file_exists($pathtofile)) {
$filesize = round(filesize($pathtofile)/1024, 2);
$filemtime = date($dateFormat, filemtime($pathtofile));
} else { die("ERROR: File does not exist, please contact the webmaster."); }
$db = mysql_connect($mysqlserver,$mysqluser,$mysqlpass) or die("Failed to connect to MySQL server");
if(mysql_select_db($mysqldbname)==false) { mysql_close($db); die("Failed to select database"); }
if($row = mysql_fetch_array(mysql_query("SELECT dc FROM downloadcount WHERE filename='".$file."'"))) { $dc = $row[dc]; } else { $dc = 0; }
if(isset($_GET['file']) && $_GET['act']=="download") {
$downloadfile = $urlPath.$file;
if(mysql_result(mysql_query("SELECT COUNT(filename) FROM downloadcount WHERE filename='".$file."'"),0)) {
mysql_query("UPDATE downloadcount SET dc=dc+1 WHERE filename='".$file."'");
} else {
mysql_query("INSERT INTO downloadcount (filename,dc) VALUES ('".$file."','1')");
}
header ("Location: ".$downloadfile);
}
} else { die("ERROR: Invalid file extension"); }
mysql_close($db);
return array(path=>"\"download.php?file=".$file."& act=download\" target=\"_top\"",file=>$file,size=>$filesize ."KB",modified=>$filemtime,dcount=>$dc);
}
?>