Skip to Content Skip to Menu

Download individual CBgallery folders into a .zip

  • jcrimmel
  • jcrimmel
  • OFFLINE
  • Posts: 55
  • Thanks: 10
  • Karma: 2
1 month 1 week ago #340221 by jcrimmel
Any guidance on how to accomplish the following?

Displaying a button/link in each CBgallery folder for the displayed user that will allow the viewing user to download all images/media in that gallery folder. I use my install as more of a CMS system where admins update customer's profiles, and sometimes they need to create a .zip of all of the images in a particular folder (ie Before and After image folders). The current storage structure saves all of the images/media on the server under each uploading user by the file name, so they wouldn't be able to distinguish the files they need if they had FTP access. I understand they can download each 1 by 1, but I was hoping you might have an idea that might get me moving in the right direction. I assume I would need to write some PHP script to accomplish this and just wondering if you had any thoughts or suggestions on this?

Thanks as always.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48926
  • Thanks: 8367
  • Karma: 1453
1 month 1 week ago #340222 by krileon
It's not really meant for file management like that so it has no features for that. I'd recommend using CB Package Builder, which can be used as a true file manager and supports versioned files. CB Gallery is currently undergoing a rewrite though and will look into a way to do mass exports as it's necessary anyway for more GDPR compliance.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: jcrimmel

Please Log in or Create an account to join the conversation.

  • jcrimmel
  • jcrimmel
  • OFFLINE
  • Posts: 55
  • Thanks: 10
  • Karma: 2
1 month 1 week ago - 1 month 6 days ago #340225 by jcrimmel
I can appreciate that I'm not using it as designed and I think that just speaks to the power and flexibility of CB, honestly. With a little creativity, you can build anything. 

I did write some PHP that ended up working pretty well. I wouldn't recommend using this on a site open to the public, but it's a good temp fix for me right now. Since I can't publish a module to just the Galley tab of a profile, I published a module in Debug and have the code written to run when the current URL meets a requirement found only when the CBgalley folders are displayed. It pulls the folder id from the URL, finds all of the matching items in the database for that folder, builds download URLs out of the info in the database, and downloads all of those when you click the displayed button. Quick and dirty using just a joomla module and Sourcerer by Regular Labs, without touching any CB files.

Code:
[source] <?php // Database connection parameters $host = 'localhost'; $user = 'XXXXXXX'; $password = 'XXXXXXX'; $db = 'XXXXXXX'; $dbprefix = 'XXXXXXX_'; $tableName = $dbprefix . 'comprofiler_plugin_gallery_items'; // Table name with prefix // Create a new MySQLi connection $database = new mysqli($host, $user, $password, $db); // Check if connection is successful if ($database->connect_errno) {     die('Failed to connect to MySQL: ' . $database->connect_error); } // Get the current URL $currentUrl = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // Check if the current URL contains the specified substring $expectedSubstring = "XXXXXXX/index.php/cb-profile/pluginclass/cbgallery?action=folder&func=show&id="; if (strpos($currentUrl, $expectedSubstring) !== false) {     // Extract Folder ID from the URL     preg_match('/show&id=([0-9]+)&gallery=/', $currentUrl, $matches);     $folderId = $matches[1] ?? null;     if ($folderId) {         // Query to find all matching rows in the database         $query = "SELECT id FROM $tableName WHERE folder = ?";         $stmt = $database->prepare($query);         if (!$stmt) {             die('Failed to prepare SQL statement.');         }         $stmt->bind_param('i', $folderId);         $stmt->execute();         $result = $stmt->get_result();         // Array to store file URLs         $fileUrls = ;         $baseUrl = "XXXXXXX/index.php?option=com_comprofiler&view=pluginclass&plugin=cbgallery&action=item&func=download&Itemid=111&format=raw&id=";         while ($row = $result->fetch_assoc()) {             $fileUrls = $baseUrl . $row['id'];         }         // Output the HTML with a "Download" button at the bottom left         echo '<!DOCTYPE html>';         echo '<html lang="en">';         echo '<head>';         echo '<meta charset="UTF-8">';         echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';         echo '<title>Download Files</title>';         echo '<style>';         echo 'body { margin: 0; padding: 0; height: 100vh; }';         echo '.download-button { position: fixed; bottom: 10px; left: 10px; padding: 10px 20px; background-color: #81A1C1; color: white; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; }';         echo '.download-button:hover { background-color: #81A1C1; }';         echo '</style>';         echo '<script>';         echo 'function downloadFiles(urls) {';         echo '  urls.forEach(function(url, index) {';         echo '    setTimeout(function() {';         echo '      var a = document.createElement("a");';         echo '      a.href = url;';         echo '      a.download = "";';         echo '      document.body.appendChild(a);';         echo '      a.click();';         echo '      document.body.removeChild(a);';         echo '    }, index * 200);'; // Delay each download by 200ms         echo '  });';         echo '}';         echo 'function initiateDownload() {';         echo '  var urls = ' . json_encode($fileUrls) . ';';         echo '  downloadFiles(urls);';         echo '}';         echo '</script>';         echo '</head>';         echo '<body>';         echo '<button class="download-button" onclick="initiateDownload()">Download all files in this folder</button>';         echo '</body>';         echo '</html>;         } else {        die('Invalid Folder ID.');       } } // Close the database connection $database->close(); ?> [/source]
Last edit: 1 month 6 days ago by jcrimmel.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum