, 당신은 우편을 만들기위한 모든 코드를 배치합니다 download_zip.php
파일의 URL을 배치합니다. 단일 포스트 페이지에서
:
변수
'model_id'
에서
<a href="<?php echo site_url().'/download_zip.php?model_id='.$post->ID; ?>">Download ZIP</a>
는, 단일 게시물의 게시물 ID를 배치합니다.
이제 wordpress setup의 루트에 download_zip.php
파일을 만들고 여기에 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
당신이
$index_file
변수에 이미지의 경로를 정의하는
$explode
변수에
url
을 깰 수 있도록 내부 &는 업로드 디렉토리를 정의합니다.
그리고 에 저장된 destination path
변수가 올바른지 확인하십시오.
희망, 도움이 될 수 있습니다.
다른 곳으로 가서 묻고있는 것을 알아 내려고 묻는 질문은 적절하지 않습니다. 코드 관련 문제가있는 경우 여기 ** 관련 ** 코드를 게시물 자체에 게시하고 해당 코드와 관련된 특정 질문을하십시오. [ask] 및 [mcve]를 참조하십시오. –
어디서 붙어 있는지 정확히 설명해야합니다. –
당신은 이미지 검색을위한 사용자 정의 필드 코드를 제공 할 수 있습니다. 단지 리피터 이미지 하위 필드 또는 다른 이미지 사용자 정의 필드에 있는지 확인하기 만하면 필요한 코드를 제공 할 수 있습니다. –