I am using localhost, and I want to download the files from it, selecting multiple files using checkbox, and downloading it to a zip file, I have gone through related questions but it's still not solving the problem.
This is the relevant lines for index page
<form action="download.php" method="post">
<tr>
<td><a href="FontFamily.php?id=<?php echo $Font_Family;?>"><?php echo $Font_Family; ?></a></td>
<td><a href="Font.php?id=<?php echo $id; ?>"><?php echo $filename; ?></a></td>
<td><img src="Font_Example.php?id=<?php echo $id; ?>" width="500" height ="100"></td>
<td align="center" ><input type="checkbox" name="files[]" value="<?php echo $Font_Name ?>"/></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="submit" name="formSubmit" value="Download" ></td>
</tr>
</form>
And this is the codes for download.php, the codes are combination of the codes that I found online and here.
<?php
$error = ""; //error holder
if(isset($_POST['formSubmit']))
{
$post = $_POST;
$file_folder = "c:\fonts\Arial"; // folder to load files
if(extension_loaded('zip'))
{
// Checking ZIP extension is available
if(isset($post['files']) and count($post['files']) > 0)
{
// Checking files are selected
$zip = new ZipArchive(); // Load zip library
$zip_name = time().".zip"; // Zip name
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE)
{
// Opening zip file to load files
$error .= "* Sorry ZIP creation failed at this time";
}
foreach($post['files'] as $file)
{
$zip->addFile($file_folder.$file); // Adding files into zip
}
$zip->close();
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_name);
// remove zip file is exists in temp path
}
else
$error .= "* Please select file to zip ";
}
else
$error .= "* You dont have ZIP extension";
}
?>
When I download the zip file, the size correct but the file can't be open when I use notepad to open to check the error it shows this
Warning: readfile(1371612622.zip): failed to open stream: No such file or directory in C:\xampp\htdocs\FontLibrary\download.php on line 29
Line 29 is
readfile($zip_name);