获取zip文件的内容并将其回显给用户


Get content of a zip file and echo it to user

我想创建一个下载链接我所有的文件都是zip但是我不想让用户知道我的下载链接在哪里

所以我想要得到zip文件的内容并返回zip头给用户下载我怎么做呢?

您应该使用"download.php?get="。base64_encode(文件名)当用户点击"download zip"时,你用标题("Location: download.php?get=")重定向他。Base64_encode ($url)到该页。头文件,在这里

$filename = base64_decode($_GET[get]);
$filepath = "/var/www/domain/httpdocs/download/path/";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename='"".$filename."'"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
ob_end_flush();
@readfile($filepath.$filename);

与其尝试头文件,不如下载一些" ready for use "的php类。然后你可以这样做:

$fileDown = new PHPFileDownload(null, null, 'myFileName', null, 'mypath/myfile.txt');
$fileDown->exportData();