I have a form from which, we get the data from users. Images are stored as blob in database. Now, I want all of the responded images to my local storage (computer).
<?php
include 'config.php';
session_start();
$table_name = $_SESSION["table"];
$zip = new ZipArchive();
$ZipFileName = $table_name . '.zip';
if ($zip->open($ZipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
echo "Cannot Open";
}
$zip->addEmptyDir('newFolder');
$query = mysqli_query($con, "SELECT * FROM $table_name");
while($row = mysqli_fetch_assoc($query)) {
$temp = $row['student_id'] . '.jpg';
$zip->addFromString($temp, $row['photo']);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=' . $ZipFileName);
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-length: " . filesize($ZipFileName));
?>
Zip file is downloaded, but at the time of extraction it shows error. When I tried to download only one image it shows no preview. How can I download all the blob files as images to my computer (a zip file)?