The funcs file
This file contains ALL of our functions, including our main lib functions that we need to pull all the data we need, and also our lovely template bits from our database.
I have commented this code so that you can see what each class and functions does, so lets get on..
Simply add the below code to the funcs.php file.
<?php
class lib {
// In this class we will load all the functions that calls all the main functions.
public function getswitch() {
// In this function we shall create the switch.
switch($_GET['action']) {
case 'download':
$dlsys->lib = new lib;
$dlsys->lib->getfiledl();
break;
case 'view':
$dlsys->lib = new lib;
$dlsys->lib->viewfile();
break;
default:
$dlsys->lib = new lib;
$dlsys->lib->getfiles();
break;
}
}
public function getfiles() {
// In this function we will fetch all the files that are in the database.
include "dbcon.php";
$getfiles="select * from files";
$resultfiles=mysql_query($getfiles) or die(mysql_error());
echo '
';
while($file=mysql_fetch_array($resultfiles)){
$filename = $file['filename'];
echo "";
}
echo "
File Title | Uploaded |
";
echo "".$file['title']." (";
echo filesize("uploads/$filename");
echo "BYTES)";
echo " | ";
echo $file['uploaded'];
echo " |
";
}
public function viewfile() {
// In this function we shall fetch a single row from the database to view a file.
include "dbcon.php";
$fileid = $_GET['file'];
$viewfile = mysql_query( "SELECT `id`, `title`, `desc` FROM `files` WHERE `id` = '{$fileid}' ORDER BY `id` DESC LIMIT 1" ) or die( 'Query Error: ' . mysql_error());
$view = mysql_fetch_object( $viewfile );
echo '
';
}
public function getfiledl() {
// In this file we shall actually download the file that is passed in the URL.
include "dbcon.php";
$file = $_GET['file'];
$getfile="select * from files where id='$file'";
$resultfile=mysql_query($getfile) or die(mysql_error());
while($dl=mysql_fetch_array($resultfile)){
echo "You are now downloading
".$dl['title'].". Your download should start in 5 seconds!";
echo '';
}
}
}
class templates {
// In this class we will load the template bits that makes the system looks a bit nicer.
public function head() {
// In this function we fetch the header template bit.
include "dbcon.php";
$gethead="select * from templates";
$resulthead=mysql_query($gethead) or die(mysql_error());
while($tpl=mysql_fetch_array($resulthead)){
echo $tpl['header'];
}
}
public function foot() {
// In this function we fetch the footer template bit.
include "dbcon.php";
$getfoot="select * from templates";
$resultfoot=mysql_query($getfoot) or die(mysql_error());
while($tpl=mysql_fetch_array($resultfoot)){
echo $tpl['footer'];
}
}
}
?>
Now you can save this file.
As you can see, this file contains the bulk of the functions we use to create our download system.
Lets check out the conclusion.