I have the following image gallery in ACF:
$slider = get_field( 'slider' );
I need to create a function so that with a single click, the entire image gallery is turned over to a .zip file. Anyone have something similar? I've found some things, but for some reason it doesn't work. Thanks.
EDIT:
I have tried to implement this:
<?php
if ( $slider ) :
$destination = 'downloads/' . sanitize_title( get_the_title() ) . '.zip';
if ( file_exists( $destination ) ) {
echo '<a href="' . esc_url( home_url( '/' ) ) . $destination . '" class="download-link" download>DOWNLOAD ALL</a>';
} else {
$files = array();
foreach ( $slider as $singlefile ) {
$files[] = get_attached_file( $singlefile['ID'] );
}
if ( count( $files ) ) {
$zip = new ZipArchive();
$zip->open( $destination, ZipArchive::CREATE );
foreach ( $files as $file ) {
if ( file_exists( $file ) ) {
$new_filename = substr( $file, strrpos( $file, '/' ) + 1 );
$zip->addFile( $file, $new_filename );
}
}
$zip->close();
echo '<a href="' . esc_url( home_url( '/' ) ) . $destination . '" class="download-link" download>DOWNLOAD ALL</a>';
} else {
echo 'no files found';
}
}
endif;
?>
But when the file is downloaded, I receive a download error and I don't know what I am doing wrong.