我正在使用localhost,我想从中下载文件,使用复选框选择多个文件,然后将其下载到zip文件,我已经解决了相关问题,但仍然无法解决问题。
这是索引页面的相关行
<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>
这是download.php的代码,代码是我在网上和这里找到的代码的组合。
<?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";
}
?>
当我下载zip文件时,大小正确,但是当我使用记事本打开检查错误时,文件无法打开显示此
警告:readfile(1371612622.zip):无法打开流: C:\ xampp \ htdocs \ FontLibrary \ download.php 中没有此类文件或目录第 29
行第29行
readfile($zip_name);