<?php
/*
Copyright (c) 2005: Michael Puff
Url: [
url]http://www.luckie-online.de[/
url]
Mail: [email]mpuff@luckie-online.de[/email]
Version: 2.0 - 2005-11-06
*/
//
// Returns the lates file from a given directory
//
function newestfile($folder,$number=0)//$folder endet auf \ oder /
{
$Docs=Array();
$
handle=opendir($folder);
$Doccount=0;
while (false !== ($file = readdir ($
handle)))
{
if ($file[0] != "." && $file != 'index.php')
{
$Docs[$Doccount]=$file;
$Time[$Doccount]=filemtime($folder.$Docs[$Doccount]);
$Doccount++;
}
}
closedir($
handle);
array_multisort($Time,SORT_DESC,$Docs);
return $Docs[$number];
}
//
// Returns the title of a given
HTML-file
//
function GetTitleFromHTML($htmlfile)
{
$content = file_get_contents($htmlfile);
$start = strpos(strtolower($content),"<title>");
$end = strpos(strtolower($content),"</title>");
if (($start !== false) and ($end !== false))
return substr($content,$start+7,$end-$start-7);
else
return "";
}
//
// Returns the size in bytes of a given directory
//
function directory_size($nomrep){
$dossier = @opendir($nomrep);
$file_size_up = 0;
while ($Fichier = @readdir($dossier)){
if ($Fichier != "." && $Fichier != ".."){
if ($Fichier){
$file_size_up += filesize($nomrep."/".$Fichier);
}
}
}
@closedir($dossier);
return $file_size_up;
}
//
// Formats the filesize in a more readable format
//
function format_filesize( $filesize )
{
$filesize = (int)$filesize;
$units = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$tot_units = (count($units) - 1);
$pass = 0; // set zero, for Bytes
while( $filesize >= 1024 && $pass < $tot_units )
{
$filesize /= 1024;
$pass++;
}
return round($filesize, 2) .''. $units[$pass];
}
//
// Returns the sub-directories of a given directory
//
function ListDirs($dir)
{
$dirs=Array();
$
handle=opendir($dir);
$count=0;
while(false !== ($s = readdir($
handle)))
{
if (is_dir($s) && ($s[0] != '.'))
{
$dirs[$count] = $s;
$count++;
}
}
closedir($
handle);
array_multisort($dirs, SORT_ASC, $dirs);
return $dirs;
}
//
// Returns the files in a given directory
// Valid values for $SortOrder: name, time, size
//
function ListFiles($dir, $SortOrder)
{
$files=Array();
$
handle=opendir($dir);
$count=0;
while(false !== ($file = readdir($
handle)))
{
if (is_file($dir.'/'.$file) && ($file != 'index.php'))
{
$files[$count] = $file;
$Time[$count]=filemtime($dir.'/'.$file);
$Size[$count]=filesize($dir.'/'.$file);
$count++;
}
}
closedir($
handle);
if ($SortOrder == 'name')
{
array_multisort($files, SORT_ASC, $files);
}
elseif ($SortOrder == 'time')
{
array_multisort($Time, SORT_DESC, $files);
}
elseif ($SortOrder == 'size')
{
array_multisort($Size, SORT_ASC, $files);
}
return $files;
}
function PickImage($Filename)
{
$s = pathinfo($Filename);
$ext = $s["extension"];
switch ($ext)
{
case "pdf": return "image/dir_pdf.png"; break;
case "zip": return "image/dir_zip.png"; break;
case "exe": return "image/dir_exe.png"; break;
default: return "image/dir_default.png"; break;
}
}
?>