如何解决PHP Archive ZIP 在 MAC 上打开,但不在 Windows 上打开
我有以下代码循环遍历图像 URL 并将图像添加到 ZIP。然后它会自动下载。
我遇到的问题是它在我的 MACBook (Chrome) 上打开,但不能在 Windows (Chrome) 上打开。
有没有人知道哪里出了问题。
if (array_key_exists("id",$_GET)) :
$author_id = trim($_GET["id"]);
$author_name = trim($_GET["user"]);
$pictures = new WP_Query( array( 'author' => $author_id,'post_type' => 'attachment','post_status' => 'inheret','posts_per_page' => -1 ) );
if ( $pictures->posts ) :
# create new zip opbject
$zip = new ZipArchive();
# create a temp file & open it
$tmp_file = tempnam('.','');
$zip->open($tmp_file,ZipArchive::CREATE);
foreach ( $pictures->posts as $picture ) :
if (wp_get_attachment_image_url($picture->ID,'full')) :
$files = array(wp_get_attachment_image_url( $picture->ID,'full' ));
if ($files) :
//echo $files;
# loop through each file
foreach($files as $file){
# download file
$download_file = file_get_contents($file);
#add it to the zip
$zip->addFromString(basename($file),$download_file);
}
endif;
endif;
endforeach;
$zip->close();
ob_clean();
$datestamp = date("d-M-Y",time());
# send the file to the browser as a download
header("Cache-Control: no-cache,must-revalidate"); // HTTP/1.1
header("Expires: Sat,26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-disposition: attachment; filename=backup-contributor-'. $author_name .'-'.$datestamp.'.zip');
header('Content-type: application/zip');
readfile($tmp_file);
endif;
endif;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。