I have a WordPress site where users are gonna be able to download one, or multiple pdf files. So far I just coded without using any WordPress functionalities and with having the files on my computer. But in the future, I want to be able to add a file using Advanced Custom Fields (or something similar) which means that I won't have the files in a folder and will have to use URL's instead. At least I think? And when I use the same code, but with URL's (see below), it doesn't work.
So how can I create a zip file from a URL using ZipArchive?
<?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>