所以我正在为字体做一个本地主机网站,我设法让用户将多个文件选择到购物车中,如果它们来自同一个文件夹,例如 C:/fonts/a 或 C:/fonts/ b 但是如果a和b都有文件,则无法下载
那么有可能做到这一点吗?比如从 a 和 b 下载选定的文件
下面是我的 download.php 代码
<?php
include 'dbfunctions.php';
if (!$link) {
die(mysqli_error($link));
}
$sql="SELECT id, Font_Name, Font_Family
FROM font";
$result = mysqli_query($link, $sql) or die(mysqli_error($link));
while($row = mysqli_fetch_array($result)){
$Font_Family = $row['Font_Family'];
$a = file_get_contents('./a.txt');
$file_dir = file_get_contents('./font_path.ini');
$path = $file_dir.$Font_Family.$a;
$error = ""; //error holder
if(isset($_POST['createpdf']))
{
$Font_Family = $_POST['Font_Family'];
}
$file_folder = $path;// 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,pathinfo($file,PATHINFO_BASENAME));
readfile($path);
}
$zip->close();
if(file_exists($zip_name))
{
// 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
unlink($zip_name);
}
}
else
$error .= "* Please select file to zip ";
}
else
$error .= "* You dont have ZIP extension";
}
?>
fontpath.ini 是 c:\fonts\
a 只是 \ 因为当我写 \
Font_Family 是 c:\fonts\ 内的不同文件夹名称时 php 给我带来了问题,
所以路径就像 C:\fonts(此处的任何文件夹名称) \