Domanda

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;  
    }`
È stato utile?

Soluzione

<?php
$file = "file.zip";
header('Content-type: application/x-download');
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Content-Length: '.filesize($file));
readfile($file);
?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top