簡體   English   中英

如何從php的Localhost下載一個Zip文件?

[英]How can I download a Zip file from Localhost in php?

我正在嘗試從本地主機下載一個zip文件。該文件正在下載中,但在打開時顯示錯誤消息“ invalid”。 我正在使用以下代碼:-

 $filename = "markers.zip";  
`if(file_exists($filename) && is_readable($filename)){  
        header("Content-Disposition: attachment; filename=".basename($filename));  
        header("Content-Type: application/force-download");  
        header("Content-Type: application/zip");  
        header("Content-Description: File Transfer");  
        header("Content-Length: " . filesize($filename));  
        flush();  
        $fp = fopen($filename, "r");  
        while (!feof($fp))  
        {  
            echo fread($fp, 65536);  
            flush();  
        }  
        fclose($fp);  
        exit;  
    }`
<?php
$file = "file.zip";
header('Content-type: application/x-download');
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Content-Length: '.filesize($file));
readfile($file);
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM