我正在尝试从wordpress中的帖子附件创建一个zip文件.
我已尝试过以下两种方法 - 但它没有结果(没有错误消息,没有创建文件) - 我做错了什么(再次......)
我不认为那些是wordpress中的帖子附件的事实与它有关 - 因为那些方法也失败了普通文件.为什么? - >看到答案.
$files_to_zip = array();// create files array
//run a query
$post_id = get_the_id();
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post_id
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$files_to_zip [] = wp_get_attachment_url( $attachment->ID ); // populate files array
}
}
print_r($files_to_zip);
$zip = new ZipArchive;
$zip->open('file.zip', ZipArchive::CREATE);
foreach ($files_to_zip as $file) {
$zip->addFile($file);
}
$zip->close();
Run Code Online (Sandbox Code Playgroud)
还有这个方法:
$files_to_zip = …Run Code Online (Sandbox Code Playgroud)