0
我有一个WordPress网站,用户可以下载一个或多个PDF文件。到目前为止,我只是编码而不使用任何WordPress的功能,并在我的电脑上有文件。但在将来,我希望能够使用高级自定义字段(或类似的东西)来添加文件,这意味着我不会将文件放在文件夹中,而必须使用URL。至少我觉得呢? 而当我使用相同的代码,但与URL(见下文),它不起作用。使用ZipArhive作为网址的Zip文件
那么如何使用ZipArchive从URL创建一个zip文件?
<?php
if(isset($_POST['createzip']))
{
$files = $_POST['files'];
$zipname = time().".zip"; // Zip name
$zip = new ZipArchive(); // Load zip library
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
}
$zip->close();
// push to download the zip
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
}
?>
<h1> hej här kan du zippa lite filer</h1>
<form name="zips" method="post">
<input type="checkbox" name="files" value="http://www.unstraight.org/wp-content/uploads/2015/08/seger3.jpg">
<p>Seger</p>
<input type="checkbox" name="files" value="http://www.unstraight.org/wp-content/uploads/dlm_uploads/2015/12/Ovningar-medelsvara.pdf">
<p>Övningar </p>
<input type="checkbox" name="files" value="http://www.unstraight.org/wp-content/uploads/2015/07/User-Agreement-.pdf">
<p>Medlemskort </p>
<input type="checkbox" name="files[]" value="men.pdf">
<p>Män och Jämställdhet </p>
<input type="submit" name="createzip" value="Download as ZIP">
</form>