小编Ted*_*6db的帖子

PHP > 下载 ZIP:网络错误

我的 php 代码有一个大问题,我使用 html 表单来获取“文件名”,工作完美,但我的问题是:当我启动下载时,所有浏览器都下载 zip 文件,并出现网络错误,例如:578ko / 600ko:网络错误。

<?php
$dir = "lol/"; // trailing slash is important
$file = $dir .$_POST['filename'] ;

if (file_exists($file)) {
    header('Pragma: public');
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Transfer-Encoding: binary");
    header("Content-type: application/zip");
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Cache-Control: must-revalidate');
    header('Content-Length: ' . filesize($file));

    readfile($file);

} else {
    echo "Le fichier $file n'existe pas.";
}
exit;
?>
Run Code Online (Sandbox Code Playgroud)

php

2
推荐指数
1
解决办法
1412
查看次数

标签 统计

php ×1