Publishing System Settings Logout Login Register
OOP PHP & MySQL Download System
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on April 20th, 2012
2563 views
PHP Coding
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 TitleUploaded
"; 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 '
File Title'.$view->title.'
File Description'.$view->desc.'
 

Download '.$view->title.'!

'; } 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.

Next Page
Pages: 1 2 3 4 5
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Andy Rixon

My name is Andy Rixon and I have been into developing PHP and MySQL Application for about 5 years, I am still learning new things everyday.
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top