小编典典
我遇到了同样的问题,但最终找到了一个不太明显的解决方案,决定在这里分享。
我遇到了很棒的zip.lib.php/ unzip.lib.php脚本,它们phpmyadmin都位于“库”目录中。
使用zip.lib.php对我来说是一种魅力:
require_once(LIBS_DIR . 'zip.lib.php');
...
//create the zip
$zip = new zipfile();
//add files to the zip, passing file contents, not actual files
$zip->addFile($file_content, $file_name);
...
//prepare the proper content type
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=my_archive.zip");
header("Content-Description: Files of an applicant");
//get the zip content and send it back to the browser
echo $zip->file();
此脚本允许下载zip,而无需将文件作为真实文件或将zip本身保存为文件。
遗憾的是,此功能不是更通用的PHP库的一部分。
更新: 确保从zip.lib.php开头删除以下检查,否则脚本将终止:
if (! defined('PHPMYADMIN')) {
exit;
}
2020-05-29