#################################################################
# #
# PHP Easy Download V1.00.05 #
# index.php #
# #
# By Paul Alger #
# webmaster@ironclad.net #
# #
#################################################################
require("file_info/config.php");
# Start timing code.
#-------------------
$t_start = array_sum(explode(' ', microtime()));
if ($force_download == "true"){
$dnld = "1";
}ELSE{
$dnld = "";
}
# Get input from user.
#---------------------
$admin = $_GET["admin"];
$rpp1 = $_POST["D2"]; #records per page
$rpp2 = $_GET["rpp"]; #records per page
$sortorder1 = $_GET["so"]; #sort order
$sortorder2 = $_POST["D1"]; #sort order
$search = $_POST["T1"]; #search term
$c1 = $_POST["C1"]; #Checkbox to search thru both filename and description.
$match = 0;
# Open header file (if it exsists) and display it.
#-------------------------------------------------
if (file_exists($header)){
$newfile = fopen($header,"r");
$content = fread($newfile, filesize($header));
fclose($newfile);
print $content;
}
$sortorder1 = (ucfirst($sortorder1));
$sortorder2 = (ucfirst($sortorder2));
# Set sort order depending on user input.
#----------------------------------------
# Default sort order is Alphabetical.
#------------------------------------
if ((!$sortorder1) && (!$sortorder2)){
$sortorder = "Alphabetical";
$so = "&so=Alphabetical";
}
# Sort by filesize and date.
#---------------------------
if ($sortorder2){
$sortorder = $sortorder2;
$so = "&so=$sortorder";
}
# Sort by # of times the file has been Accessed.
#-----------------------------------------------
If ($sortorder1){
$sortorder = $sortorder1;
$so = "&so=$sortorder";
}
# Get current page to be displayed.
#----------------------------------
$currentpage = $_GET["page"];
if ($currentpage < 1){
$currentpage = 1;
}
# If no records per page is selected, set the default.
#-----------------------------------------------------
if ((!$rpp1) && (!$rpp2)){
$records_per_page = $defaultrpp;
$rpp3 = "&rpp=$records_per_page";
}
# Otherwise, set the user defined record per page.
#--------------------------------------------------
If ($rpp2){
$records_per_page = $rpp2;
$rpp3 = "&rpp=$records_per_page";
}
If ($rpp1){
$records_per_page = $rpp1;
$rpp3 = "&rpp=$records_per_page";
}
# Read current directory.
#------------------------
$d = dir(".");
while (false !== ($file = $d->read())) {
if ($file != "." && $file != "..") {
# Get all the file attributes.
#-----------------------------
$size = filesize($file);
$type = filetype($file);
$ext = strrchr($file,'.');
$modified = stat("$file");
$displayname = str_replace (strrchr ($file, "."), "", $file);
# If it is a file (not a directory) and the file extention is in $display_list..
#-------------------------------------------------------------------------------
if (($type == file) && (preg_match ("/$ext/i", $display_list))) {
# Format the Dispayed filename.. replace underscore with a space
# and Change each word to start with an upper case letter.
#---------------------------------------------------------------
$displayname = str_replace("_"," ",$displayname);
$displayname = strtolower($displayname);
$displayname = ucwords($displayname);
$filedate = date("d-m-y",$modified[9]);
# See if description file exsists. If not, create it.
#---------------------------------------------------------------------------
$filedescription = "./file_info/descriptions/$file.0";
if (!file_exists($filedescription)) {
$newfile = fopen($filedescription,"w");
$newdescription = "0|- - -|http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=$displayname &btnI=I%27m+Feeling+Lucky|".time();
fwrite($newfile, $newdescription);
fclose($newfile);
$contents = $newdescription;
$accesses = 0;
}
ELSE
{
# If the file does exist, read its data.
#---------------------------------------
$newfile = fopen($filedescription,"r");
$content = fread($newfile, filesize($filedescription));
fclose($newfile);
$data = explode("|", $content);
$accesses = $data[0];
$upload_date = $data[3];
}
# Format the output depending on sort order and search criteria.
#---------------------------------------------------------------
if ((!$search) && ($sortorder == "Alphabetical")){
$filename[$totalfiles] = "$displayname|$displayname|$file|$ext|$size|$filedate|$content|$upload_date";
}
if ((!$search) && ($sortorder == "File Size")){
$filename[$totalfiles] = "$size|$displayname|$file|$ext|$size|$filedate|$content|$upload_date";
}
if ((!$search) && ($sortorder == "Accesses")){
$filename[$totalfiles] = "$accesses|$displayname|$file|$ext|$size|$filedate|$content|$upload_date";
}
if ((!$search) && ($sortorder == "Latest Files")){
$filename[$totalfiles] = "$upload_date|$displayname|$file|$ext|$size|$filedate|$content|$upload_date";
}
# Search both File Name and Description.
#---------------------------------------
if (($search) && ($C1)){
$searchtext = "Wynik wyszukiwania dla: \"$search\"znaleziono : $match plik(i)
";
$records_per_page = 0;
$currentpage = 1;
$pos = preg_match ("/$search/i", "$displayname$content");
if ($pos){
$filename[$totalfiles] = "$accesses|$displayname|$file|$ext|$size|$filedate|$content|$upload_date";
$match++;
}
}
# Search File Name Only.
#-----------------------
if ($search){
$searchtext = "Wynik wyszukiwania dla: \" $search \" znaleziono : $match plik(i)
";
$records_per_page = 0;
$currentpage = 1;
$pos = preg_match ("/$search/i", "$displayname");
if ($pos){
$filename[$totalfiles] = "$accesses|$displayname|$file|$ext|$size|$filedate|$content|$upload_date";
$match++;
}
}
$totalbytes = $totalbytes + $size;
$totalfiles++;
}
}
}
# Sort by filename.
#------------------
if (($filename) && ($sortorder == "Alphabetical")){
sort ($filename,SORT_REGULAR);
reset ($filename);
$select1 = "selected";
$select2 = "";
$select3 = "";
$select4 = "";
$match = 1;
}
# Sort by file Size.
#-------------------
if (($filename) && ($sortorder == "File Size")){
rsort ($filename,SORT_NUMERIC);
reset ($filename);
$select1 = "";
$select2 = "selected";
$select3 = "";
$select4 = "";
$match = 1;
}
# Sort by accesses.
#------------------
if (($filename) && ($sortorder == "Accesses")){
rsort ($filename,SORT_NUMERIC);
reset ($filename);
$select1 = "";
$select2 = "";
$select3 = "selected";
$select4 = "";
$match = 1;
}
# Sort by Date.
#--------------
if (($filename) && ($sortorder == "Latest Files")){
rsort ($filename,SORT_NUMERIC);
reset ($filename);
$select1 = "";
$select2 = "";
$select3 = "";
$select4 = "selected";
$match = 1;
}
# Pagination Start.
#------------------
if ($records_per_page < 1){
$records_per_page = $totalfiles + 1;
}
If ($totalfiles > $records_per_page){
$totalpages = ceil($totalfiles/$records_per_page);
$flag = 0;
if ($currentpage > $totalpages){
$currentpage = 1;
}
}ELSE{
$flag = 1;
}
# Print out the top of the form and search criteria boxes.
#---------------------------------------------------------
?>
"; print ""; print " | "; }ELSE{ print ""; print ""; print " | "; } } print "";
# Display the File Name.
#-----------------------
if ($display_filename == 1){
if ($dnld == 1){
print "$display_filename_tag\n";
print "\n";
print "$fileattr[1]$display_filename_tag_end \n"; }ELSE{ print "$display_filename_tag\n"; print "\n"; print "$fileattr[1]$display_filename_tag_end \n"; } } # Display File Description. #-------------------------- if ($display_description == 1){ print "$display_description_tag $fileattr[7] $display_description_tag_end \n"; } # Display the "More Info" link. #------------------------------ if ($display_moreinfo == 1){ print "$display_moreinfo_tagWięcej informacji$display_moreinfo_tag_end \n"; } # Display the File Type. #----------------------- //if ($display_filetype == 1){ // print "$display_filetype_tag$xtrainfo$display_filetype_tag_end\n"; //} # If admin flag is set, Print the link to edit entries. #------------------------------------------------------ //if ($admin){ // print "$display_filetype_tag$admininfo$display_filetype_tag_end\n"; //} print " |
$display_filesize_tag Rozmiar pliku: $size$display_filesize_tag_end | \n";
}
# Display Accessed.
#------------------
if ($display_accessed == 1){
print "$display_accessed_tag Pobierano: $fileattr[6] razy$display_accessed_tag_end | \n";
}
# Display File Date.
#-------------------
$file_time = date("d-m-y", $fileattr[9]);
if ($display_filedate == 1){
print "$display_filedate_tag Dodano dnia: $file_time$display_filedate_tag_end | \n";
}
print "
";
if ($flag == 0){
$previouspage = $currentpage-1;
if ($previouspage < 1){
$previouspage = 1;
}
$nextpage = $currentpage+1;
if ($nextpage > $totalpages){
$nextpage = $totalpages;
}
print " $display_pagination_tag Back | "; $z = 1; while ($z <= $totalpages){ if ($z == $currentpage){ $size = $display_selected_size; }ELSE{ $size = $display_pagination_size; } print "$z | "; $z++; } print "Next"; print "$display_pagination_tag_end |
";
}
#.Fix and format Byte Length.
#----------------------------
if ($totalbytes < pow(2,10)){
$totalsize = "$totalbytes B";
}
if ($totalbytes >= pow(2,10) && $totalbytes < pow(2,20)) {
$totalsize = round($totalbytes / pow(2,10), 2)." KB";
}
if ($totalbytes >= pow(2,20) && $totalbytes < pow(2,30)) {
$totalsize = round($totalbytes / pow(2,20), 2)." MB";
}
if ($totalbytes > pow(2,30)) {
$totalsize = round($totalbytes / pow(2,30), 2)." GB";
}
?>
Ogółem plików: echo $totalfiles; ?> Total Bytes: echo $totalsize; ?> # End of timed code here. #------------------------ $exec_time = array_sum(explode(' ', microtime())) - $t_start; $exec_time1 = (ceil($exec_time * 10000))/10000; print"Execution time: $exec_time1 sec. "; //print "Admin |