因此,我正在爲字體做一個localhost網站,並且我設法讓用戶選擇多個文件到一個購物車中,如果它們來自同一個文件夾,例如C :/ fonts/a或C:/ fonts/b但是如果有來自a和b的文件,則無法下載PHP從多個文件夾中壓縮和下載文件
那麼可以這樣做嗎?像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 \中
一個就是\自PHP給了我問題時,我只寫\
FONT_FAMILY是C內的不同的文件夾名稱:\字體\
這樣的路徑是像C:\字體(這裏取文件夾名)\
php給了你什麼問題? – DevZer0
他們只是對待'並關閉它。 – Ren