0
其实我有zipfile。但我并不需要桌面上的全部文件。我想要选择userid文件...我尝试编写下面的代码,我使用了php和mysql。如何从数据库中下载多个文件在php中
<?php
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
//echo $file_path.$files,$files."<br />";
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
require_once("config.php");
$cqurfetch=mysql_query("SELECT * FROM albums where user_id='$user_id' and accept='1'");
while($row = mysql_fetch_array($cqurfetch))
{
$file_names[] = $row['user_album_images'];
}
$archive_file_name=time().'.gallery.zip';
$file_path="/uploads/";
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
?>
$ file_names array你得到了什么?所有文件都只有$ user_id文件。 – RaMeSh 2015-04-03 11:57:27
可以请你详细说明你的问题 – RaMeSh 2015-04-03 12:08:18
我只想要$ user_id文件,不是所有文件 – 2015-04-03 12:11:07