I designed a photo gallery for a local Primary School and now that the new session has started, I have been asked to remove all the photographs and supply them on CD. Unfortunately, although I have now corrected the problem for new photos, I did not have a unique name for the photographs for each album and I need to separate them into albums. Before deleting the data from the database, I downloaded it so I could go through each of the 1000 or so entries manually and separate the photographs but that would be a long job.

Does anyone have any suggestions for me to select a series of photographs according to a database filter. The original programming was done with PHP and MySQL.

Dani AI

Generated

Brief, practical plan for (and anyone else facing the same): rebuild album groupings using the database and image metadata, then produce one download per album from the server so parents get a single file instead of hundreds of individual downloads. 's idea to provide an archive is the right direction; below is a concrete, low-risk way to implement it and extra tips for grouping images when filenames lack album info.

Quick PHP example (uses PDO and ZipArchive):

<?php
set_time_limit(0);

$pdo = new PDO('mysql:host=localhost;dbname=gallery;charset=utf8mb4', 'dbuser', 'dbpass', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

// Select rows that belong to one album (adjust WHERE to your filter)
$stmt = $pdo->prepare('SELECT id, file_path, blob_data FROM photos WHERE /* your criteria */');
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

$tmp = tempnam(sys_get_temp_dir(), 'export') . '.zip';
$zip = new ZipArchive();
if ($zip->open($tmp, ZipArchive::CREATE) !== TRUE) { exit('Could not create archive'); }

foreach ($rows as $r) {
    if (!empty($r['file_path']) && file_exists($r['file_path'])) {
        $zip->addFile($r['file_path'], basename($r['file_path']));
    } elseif (!empty($r['blob_data'])) {
        $zip->addFromString('photo-' . $r['id'] . '.jpg', $r['blob_data']);
    }
}
$zip->close();

header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="album-export.zip"');
header('Content-Length: ' . filesize($tmp));
readfile($tmp);
unlink($tmp);
exit;
?>

Grouping heuristics and workflow suggestions: if filenames are useless, cluster by upload timestamp ranges, uploader ID, and EXIF DateTimeOriginal (use exif_read_data) to reconstruct sessions. Run small automated clusters, then present batches (25–50 thumbs) in an admin page with checkboxes to confirm and assign an album_id back into MySQL. That makes future exports trivial.

Cautions and tips: run large exports from the command line or set plenty of time/memory to avoid web timeouts; ensure adequate disk space and file permissions; if images are BLOBs, add them with addFromString; sanitize names added to the archive; consider streaming libraries (ZipStream) for very large archives. See the PHP docs: ZipArchive manual and exif_read_data.

I have just had a thought, I could upload them all to my test server and use the MySQL database to filter them.............. does anyone know how to download multiple files using PHP???

Compress them into a zip, bzip, gzip file and download that. Otherwise your limited to your download managers amount.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.