<?php
/* * * * * * * *
* C O N F I G *
* * * * * * * */
$action = $_GET['action'];
$page = $_GET['page'];
$id = $_GET['id'];
$get = $_GET['get'];
$dir = $_GET['dir'];
$imagesPerPage = 5;
?>
<html>
<head>
<title>Online Gallery</title>
<style>
body { background-color: black; color: white; }
a:visited { text-decoration: none; color: white; }
a:hover { text-decoration: underline; color: white; }
a { text-decoration: none; color: white }
</style>
</head>
<body>
<?php
function createName($length = 6)
{
$pattern = 'abcdefghijklmnoprstwquxyzv1234567890';
$max = strlen($pattern) - 1;
$random = '';
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++)
$random .= $pattern[mt_rand(0, $max)];
if(file_exists("./images/{$random}"))
return createName();
return $random.'.zip';
}
function removeOldZips($minutes = 10)
{
//todo....... :(
return true;
}
removeOldZips();
$zip = new ZipArchive();
$name = createName();
//Bla bla
if(empty($action) || !in_array($action, array("zip", "view", "img")))
$action = "view";
if(empty($page) || !is_numeric($page))
$page = 1;
//Bla bla
if(strtolower($action) == "zip" && !empty($dir))
{
if(strpos($dir, "./"))
{
echo "fuuuu";
$skipZip = true;
}
if(!$skipZip)
{
if($zip->open("./zips/{$name}", ZIPARCHIVE::CREATE) !== false)
{
if($handle = opendir("./images/{$dir}"))
{
while(($file = readdir($handle)) !== false)
if(!in_array($file, array(".", "..")))
if(!is_dir($file))
$zip->addFile("./images/{$dir}/{$file}", $file);
closedir($handle);
}
$zip->close();
echo "<a href=\"./zips/{$name}\">Your package is ready.</a>";
}
else
echo "Something went wrong... Try again.";
}
}
else if(strtolower($action) == "img")
{
echo "<center><a href=\"?action=view\">Go back.</a></center>";
if(!$dir || !$id)
echo "<center>Image not found!</center>";
else
if(file_exists("./images/{$dir}/{$id}"))
echo "<img src=\"./images/{$dir}/{$id}\" alt=\"{$id}\" />";
else
echo "<center>Image not found!</center>";
}
else if(strtolower($action) == "view")
if(!$dir)
{
if($handle = opendir("./images"))
{
while(($file = readdir($handle)) !== false)
if(!in_array($file, array(".", "..")))
if(!is_dir($file))
echo "<a href=\"?action=view&dir={$file}\">{$file}</a><br />";
closedir($handle);
}
}
else
if($handle = opendir("./images/{$dir}"))
{
$files = array("");
while(($file = readdir($handle)) !== false)
if(!in_array($file, array(".", "..")))
if(!is_dir($file))
$files[] = $file;
closedir($handle);
if($files)
{
echo "<a href=\"?action=zip&dir={$dir}\">Zip This Category!</a><br />";
$pages = ceil(count($files) / $imagesPerPage);
if($page > $pages)
$page = 1;
$s = $page == 1 ? 1 : $page * $imagesPerPage - $imagesPerPage + 1;
$next = $page + 1;
$previous = $page - 1;
for($i = $s; $i < $s + $imagesPerPage; $i++)
if(!empty($files[$i]))
if($i % 5 == 0)
{
$br = false;
echo "<a href=\"?action=img&dir={$dir}&id={$files[$i]}\"><img src=\"./images/{$dir}/{$files[$i]}\" alt=\"{$files[$i]}\" title=\"\" height=\"320\" width=\"240\" border=\"0\" /></a><br />";
}
else
{
echo "<a href=\"?action=img&dir={$dir}&id={$files[$i]}\"><img src=\"./images/{$dir}/{$files[$i]}\" alt=\"{$files[$i]}\" title=\"\" height=\"320\" width=\"240\" border=\"0\" /></a> ";
$br = true;
}
else
break;
if($br)
echo '<br />';
if($page > 1)
echo "<a href=\"?action=view&dir={$dir}&page={$previous}\">Previous Page</a>";
if($pages > $page && $page > 1)
echo " | ";
if($pages > $page)
echo "<a href=\"?action=view&dir={$dir}&page={$next}\">Next Page</a>";
}
else
echo "This category is empty.";
}
else
echo "wtf zi000000000000m";
?>
</body>
</html>