【发布时间】:2011-04-28 15:48:57
【问题描述】:
可能重复:
Open file, write to file, save file as a zip and stream to user for download
我在上传文件夹中有一个 txt 文件,我需要在其中添加此文件并即时创建一个 ZIP,并提示用户下载应包含该文本文件的 Zip 文件。我该怎么做,此外还有什么提示用户下载所需的标题。任何人都可以帮助我。我使用了 PHP Manual.Iam 中的相同结构。我使用相同的函数来压缩文件“http://davidwalsh.name/create-zip-php”并且我正在编写此代码并且我收到提示进行 zip 下载但我在提取文件时收到警告消息
$zip_file = "my-archive.zip";
$file_path="../../../downloads/";
$files_to_zip = array($file_path."test_testing.txt");
$result = create_zip($files_to_zip,'my-archive.zip');
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=".$zip_file);
header("Pragma: no-cache");
header("Expires: 0");
readfile($zip_file);
警告错误消息是“此存档中的一个或多个文件使用“..”(父文件夹)作为其文件夹信息的一部分“
【问题讨论】:
标签: php