문제

I am trying to download a zip file from my localhost.The file is downloading but gives an error message "invalid" when I open it. I am using the following code:-

 $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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top