Shutting down my image host. I added a download album button to make it easier for my users.
Step one:
Create a subdomain such as
download.yourhost.com
The PHP code. Save this in a file called i.php
Go to your Chevereto Themes and in the overrides for views/album.php (located in app/themes/Peafowl) look for the share snippet and add the following:
Go to overrides/snippets and create a new file called modal_download.php and use this code
Last part is your .htaccess
RewriteEngine on
RewriteRule ^(.+)\.gif$ https://download.yourhost.com/i.php?id=$1 [R=301,L]
Step one:
Create a subdomain such as
download.yourhost.com
The PHP code. Save this in a file called i.php
PHP:
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
$id = intval($_GET['id']);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT COUNT(*) AS `image_count` FROM `chv_images` WHERE `image_album_id` = $id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$image_count = $row['image_count'];
if ($image_count > 150) {
echo "Error: Album has too many images";
} else {
// Create a new ZipArchive instance
$zip = new ZipArchive();
$zipname = 'images_' . uniqid() . '.zip'; // Random filename
if ($zip->open($zipname, ZipArchive::CREATE) !== TRUE) {
exit("Unable to create ZIP file");
}
$sql = "SELECT `image_name`, `image_extension` FROM `chv_images` WHERE `image_album_id` = $id";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
$image_name = $row['image_name'];
$image_extension = $row['image_extension'];
$image_url = "https://fluffy.nickpic.host/{$image_name}.{$image_extension}";
// Download the image
$image_data = file_get_contents($image_url);
// Add the image to the zip file
$zip->addFromString("$image_name.$image_extension", $image_data);
}
// Close the zip file
$zip->close();
// Send the zip file to the browser for download
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=' . $zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
// Delete the temporary zip file
unlink($zipname);
}
} else {
echo "No images found for album $id";
}
$conn->close();
?>
Go to your Chevereto Themes and in the overrides for views/album.php (located in app/themes/Peafowl) look for the share snippet and add the following:
PHP:
<a class="btn blue" data-modal="simple" data-target="modal-download"><span class="icon fas fa-random"></span><span class="btn-text phone-hide">Randomizer</span></a>
<?php G\Render\include_theme_file('snippets/modal_download'); ?>
Go to overrides/snippets and create a new file called modal_download.php and use this code
PHP:
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?> <?php $share_modal = function_exists('get_share_modal') ? get_share_modal() : G\get_global("share_modal"); ?> <div id="modal-download" class="hidden"> <span class="modal-box-title">Album Downloader</span> <p class="highlight margin-bottom-20 font-size-small text-align-center<?php if(is_null($share_modal["privacy"]) || $share_modal["privacy"] == "public") echo " soft-hidden"; ?>" data-content="privacy-private"><?php echo $share_modal['privacy_notes']; ?></p> Below you can grab your download link! All album images in this album will be in the downloader. You can add or remove images from the album at any time to effect the downloader. <div class="c8 phablet-c1"> <div class="input-label margin-bottom-0"> <label for="modal-share-url"><?php _se('Link'); ?></label> <input type="text" name="modal-download-url" id="modal-download-url" class="text-input" value="https://download.yourhost.com/<?php $RanAlbumID = get_album()['id']; echo $RanAlbumID; ?>.gif" data-focus="select-all"> </div> </div> </div>
Last part is your .htaccess
RewriteEngine on
RewriteRule ^(.+)\.gif$ https://download.yourhost.com/i.php?id=$1 [R=301,L]