На одной почтовой странице, поместите URL в download_zip.php
файла, в котором вы будете размещать весь код для создания молнии.
На одной странице сообщению:
<a href="<?php echo site_url().'/download_zip.php?model_id='.$post->ID; ?>">Download ZIP</a>
В переменной 'model_id'
поместите пост идентификатор одного поста.
Теперь создайте файл download_zip.php
в корне вашей настройки wordpress, где существует файл wp-config.php.
Здесь код download_zip.php
.
<?php
/*File for downloading the gallery zip files*/
$post_id = $_GET['model_id'];
require_once('wp-blog-header.php');
require_once('/wp-admin/includes/file.php');
WP_Filesystem();
$files_to_zip = array();
$zip = new ZipArchive();
$title = get_the_title($post_id);
$destination = wp_upload_dir();
//var_dump($destination);
$destination_path = $destination['basedir'];
$DelFilePath = str_replace(" ","_",$title).'_'.$post_id.'_'.time().'.zip' ;
$zip_destination_path = $destination_path."/".$DelFilePath;
if(file_exists($destination_path."/".$DelFilePath)) {
unlink ($destination_path."/".$DelFilePath);
}
if ($zip->open($destination_path."/".$DelFilePath, ZIPARCHIVE::CREATE) != TRUE) {
die ("Could not open archive");
}
//this is only for retrieving Repeater Image custom field
$row1 = get_field('acf_field_name1',$post_id);
$row1 = get_field('acf_field_name2',$post_id);
$rows = array($row1,$row2);
if($rows) {
foreach($rows as $row): ?>
<?php
$explode = end(explode("uploads",$row));
$index_file = array($destination_path,$explode);
$index_file = implode("",$index_file);
$new_index_file = basename($index_file);
$zip->addFile($index_file,$new_index_file);
endforeach;
}
$zip->close();
if(file_exists($zip_destination_path)) {
send_download($zip_destination_path);
}
//The function with example headers
function send_download($file) {
$basename = basename($file);
$length = sprintf("%u",filesize($file));
header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.$basename.'"');
header('Content-Transfer-Encoding: binary');
header('Pragma: public');
header('Content-Length: ' . $length);
set_time_limit(0);
ob_clean();
flush();
readfile($file); // "Outputs" the file.
unlink($file);
}
?>
Пожалуйста, измените этот код в соответствии с вашими требованиями, таких как get_field()
, поместите image field name
внутри него, & определить ваш каталог загрузки, так что вы можете разорвать url
в $explode
переменной для определения пути изображения в $index_file
переменной.
И, пожалуйста, также проверьте свой destination path
, сохраненный в $destination_path
, правильная переменная.
Надеюсь, это может быть полезно для вас.
Вопросы, предлагающие нам пойти куда-то еще, чтобы попытаться выяснить, что вы просите, здесь не уместны. Если у вас есть проблемы с кодом, напишите ** соответствующий ** код здесь, в самой записи и задайте конкретный вопрос, связанный с этим кодом. См. [Ask] и [mcve]. –
Вам нужно точно объяснить, где вы застряли. –
можете ли вы указать свой код поля для получения изображений, я просто хочу проверить, находятся ли они в подполе изображения повторителя или в другом пользовательском поле изображения, поэтому я могу предоставить вам необходимый для этого код. –