%PDF- %PDF-
| Direktori : /www/varak.cloud/img.varak.cloud/ |
| Current File : /www/varak.cloud/img.varak.cloud/_index.php |
<?php
function getmicrotime()
{
list($usec,$sec)=explode(" ",microtime());
return ((float)$usec+(float)$sec);
}
if (!function_exists('str_starts_with')) {
function str_starts_with($haystack, $needle) {
return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0;
}
}
function makethumb($name)
{
$max = 640;
$widthn = $max;
$heightn = $max;
//header('Content-type: image/jpeg');
list($width, $height) = getimagesize("./img/$name");
$ratio_orig = $width/$height;
if (1 > $ratio_orig)
{
$widthn = $max*$ratio_orig;
}
else
{
$heightn = $max/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($widthn, $heightn);
$image = null;
$upper = strtoupper($name);
if(strstr($upper, ".JPEG") || strstr($upper, ".JPG"))
$image = imagecreatefromjpeg("./img/$name");
else if(strstr($upper, ".PNG"))
$image = imagecreatefrompng("./img/$name");
else if(strstr($upper, ".BMP"))
$image = imagecreatefrombmp("./img/$name");
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $widthn, $heightn, $width, $height);
imagejpeg($image_p, "./thumbs/$name", 75);
}
$cols = 3;
ob_start();
$tzac=getmicrotime();
function fsize($size)
{
$jedn = array("bytes", "Kbytes", "Mbytes", "Gbytes", "Tbytes", "Pbytes");
//$size = filesize($name);
$i = 0;
while($size > 1023)
{
$size /= 1024;
$i++;
}
return sprintf("%0.2f %s", $size, $jedn[$i]);
}
$sub = str_replace("\\'", "'", ($_GET['dir']));
$path = './img/';
//$path = "/www/varak.net";
$path = $path . "$sub";
echo "<!-- PATH: $path\n";
$dh = opendir($path);
print_r($dh);
//echo " -->";
$i=1;
while ($dh && ($file = readdir($dh)) !== false) {
if($file != "." && $file != ".." && $file != "Thumbs.db") {
if (substr($file, -4, -3) == "." || substr($file, -5, -4) == ".")
// if(!is_dir($file))
{
//echo "$i. <a href=\"http://music.varak.net/$sub/$file\">$file</a> ($size) <br />";
//echo "<tr><td>$i</td><td><a href=\"$sub/$file\">$file</a><!-- INODE: ".$stat['ino']." --></td><td>$size</td><td>$date</td></tr>\n";
$files[] = $file;
}else{
//echo "$i. <a href='?dir=$sub/$file'>$file</a><br />";
$dirs[] = $file;
}
//$i++;
}
}
print_r($files);
echo "\nDirs:";
print_r($dirs);
echo " -->";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Album
</title>
</head>
<body>
<?php
if($dirs)
{
echo "<h3>Podalba</h3>\n<ul>\n";
sort($dirs);
foreach($dirs as $dir)
{
if(!file_exists("./thumbs/$sub/$dir/"))
{
mkdir("./thumbs/$sub/$dir/", 0777);
}
$dp = str_replace("'", "%27", urlencode($sub."/".$dir));
echo "<li><a href='?dir=$dp'>$dir</a></li>\n";
$i++;
}
}
?>
</ul>
<table width="960" align="center" border="0">
<?php
if($files)
{
sort($files);
$cc = 0;
foreach($files as $file)
{
if($file == "index.php") continue;
if(strtoupper(substr($file, -3)) != "JPG" && strtoupper(substr($file, -3)) != "BMP" && strtoupper(substr($file, -3)) != "PNG" && strtoupper(substr($file, -4)) != "JPEG") continue;
//echo "$i. <a href=\"http://music.varak.net/$sub/$file\">$file</a> ($size) <br />";
if($_GET['dir'])
{
$file = $_GET['dir']."/".$file;
}
if(!str_starts_with($file, "/")) $file = "/" . $file;
echo "<!-- $file -->\n";
if($cc == 0)
{
echo "<tr>\n";
}
echo "\t<td><a href=\"./img$file\" style=\"border : 0;\"><img src=\"./thumbs$file\" style=\"border : 0;\" /></a></td>\n";
$cc++;
if($cc == $cols)
{
$cc = 0;
echo "</tr>\n";
}
$i++;
// Nyni je treba vyresit vytvoreni thumbnailu :D
if(!file_exists("./thumbs$file"))
{
makethumb("$file");
}
}
}
closedir($dh);
?>
</table>
</body>
</html>
<?php
$mem = sprintf("%01.2f", memory_get_peak_usage(true)/(1024*2024));
$tkon=getmicrotime();
$time=$tkon-$tzac;
$time = sprintf("%01.4f", $time);
header("X-Time-Used: $time");
header("X-Memory-Used: $mem MBytes");
echo ob_get_clean();
?>