[英]PHP Zip and download files from multiple folder
因此,我正在一個字體的localhost網站,我設法讓用戶將多個文件選擇到購物車中,如果它們來自同一文件夾,則可以將其下載,例如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 \\
一個只是\\因為php在我寫\\時給了我問題
Font_Family是c:\\ fonts \\中的另一個文件夾名稱
所以路徑就像C:\\ fonts(這里的文件夾名)\\
您可以使用每種字體,而不管目錄如何,然后將其復制到臨時目錄,例如C:/fonts/temp/cartID/
。 然后,您可以壓縮該字體目錄(有些來自/ fonts / a,有些來自/ fonts / b)並提供下載。 然后,您將需要進行垃圾收集,即刪除臨時cartID目錄。
就是我的2美分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.