Display album download only if available
This commit is contained in:
parent
1fbbaca5d7
commit
1321def3e1
1 changed files with 50 additions and 23 deletions
73
photos.php
73
photos.php
|
@ -1,31 +1,55 @@
|
|||
<?php
|
||||
ob_start(); // Start reading html
|
||||
// Get active folder from url and prevent from seeing folders before photos/
|
||||
function getActiveFolder()
|
||||
|
||||
define("urlParam", "path");
|
||||
|
||||
// Get active path from url and prevent from seeing folders before photos/
|
||||
function getActivePath()
|
||||
{
|
||||
$dir = $_GET['folder'];
|
||||
$dir = $_GET[urlParam];
|
||||
$folders = explode(DIRECTORY_SEPARATOR, $dir);
|
||||
$currentPath = "";
|
||||
foreach ($folders as $value) {
|
||||
if ($value != "..") {
|
||||
$currentPath .= $value . DIRECTORY_SEPARATOR;
|
||||
if ($value != ".." && $value != "." && $value != "") {
|
||||
$currentPath .= DIRECTORY_SEPARATOR.$value;
|
||||
}
|
||||
}
|
||||
return $currentPath;
|
||||
}
|
||||
|
||||
// Get active folder from the active path
|
||||
function GetActiveFolder($path) {
|
||||
$dir = explode(DIRECTORY_SEPARATOR, $path);
|
||||
return $dir[sizeof($dir) - 1]; // Last item after /
|
||||
}
|
||||
|
||||
function isAlbumAvailable($path) {
|
||||
$dir = "photos".$path;
|
||||
$files = scandir($dir);
|
||||
$valid = false;
|
||||
foreach ($files as $key => $value) {
|
||||
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
|
||||
if (!is_dir($path)) {
|
||||
$valid = pathinfo($path, PATHINFO_EXTENSION) == "zip";
|
||||
if ($valid)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $valid;
|
||||
}
|
||||
|
||||
|
||||
// Get all directories in the specified path
|
||||
function getDirectories($dir)
|
||||
{
|
||||
$dir = "photos/".$dir;
|
||||
$dir = "photos".$dir;
|
||||
$files = scandir($dir);
|
||||
$displayedItems = 0;
|
||||
foreach ($files as $key => $value) {
|
||||
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
|
||||
if (is_dir($path) && $value != "." && $value != "..") {
|
||||
$folderTitle = $value;
|
||||
$folderLink = "?folder=" . getActiveFolder() . $value;
|
||||
$folderClass = "";
|
||||
$folderLink = "?".urlParam."=".getActivePath().DIRECTORY_SEPARATOR.$value;
|
||||
include("includes/photos/folder_template.php");
|
||||
$displayedItems++;
|
||||
}
|
||||
|
@ -39,16 +63,16 @@ function getDirectories($dir)
|
|||
// Get all photos in the specified path
|
||||
function getPhotos($dir)
|
||||
{
|
||||
$dir = "photos/".$dir;
|
||||
$dir = "photos".$dir;
|
||||
$files = scandir($dir);
|
||||
$displayedItems = 0;
|
||||
foreach ($files as $key => $value) {
|
||||
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
|
||||
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
|
||||
if (!is_dir($path)) {
|
||||
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
||||
if ($ext == "bmp" || $ext == "jpg" || $ext == "jpeg" || $ext == "png") {
|
||||
$imageSrc = $dir . $value;
|
||||
$imageId = "photo-" . $displayedItems;
|
||||
if ($ext == "bmp" || $ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") {
|
||||
$imageSrc = $dir.DIRECTORY_SEPARATOR.$value;
|
||||
$imageId = "photo-".$displayedItems;
|
||||
include("includes/photos/photo_template.php");
|
||||
$displayedItems++;
|
||||
}
|
||||
|
@ -66,13 +90,13 @@ function generatePath($dir)
|
|||
$folders = explode(DIRECTORY_SEPARATOR, $dir);
|
||||
$currentPath = "";
|
||||
$pathTitle = "Menu";
|
||||
$pathLink = "?folder=";
|
||||
$pathLink = "?".urlParam."=";
|
||||
include("includes/photos/path_template.php");
|
||||
foreach ($folders as $value) {
|
||||
if ($value != "") {
|
||||
$pathTitle = $value;
|
||||
$currentPath .= $value . DIRECTORY_SEPARATOR;
|
||||
$pathLink = "?folder=" . $currentPath;
|
||||
$currentPath .= DIRECTORY_SEPARATOR.$value;
|
||||
$pathLink = "?".urlParam."=".$currentPath;
|
||||
include("includes/photos/path_template.php");
|
||||
}
|
||||
}
|
||||
|
@ -107,21 +131,24 @@ function generatePath($dir)
|
|||
<ul class="photos_path">
|
||||
<li><p>Chemin : </p></li>
|
||||
<?php
|
||||
generatePath(getActiveFolder());
|
||||
generatePath(getActivePath());
|
||||
?>
|
||||
</ul>
|
||||
<div class="photos_folder">
|
||||
<?php
|
||||
getDirectories(getActiveFolder());
|
||||
getDirectories(getActivePath());
|
||||
?>
|
||||
</div>
|
||||
<div id="download_album">
|
||||
<i class="fas fa-download"></i>
|
||||
<p>Télécharger l'album</p>
|
||||
</div>
|
||||
<?php if(isAlbumAvailable(getActivePath())): ?>
|
||||
<a download="" href="photos<?php echo getActivePath().DIRECTORY_SEPARATOR.GetActiveFolder(getActivePath())?>.zip" id="download_album">
|
||||
<i class="fas fa-download"></i>
|
||||
<p>Télécharger l'album</p>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="photos">
|
||||
<?php
|
||||
getPhotos(getActiveFolder());
|
||||
getPhotos(getActivePath());
|
||||
?>
|
||||
</div>
|
||||
<script src="assets/scripts/photosScript.js"></script>
|
||||
|
|
Loading…
Reference in a new issue