Frage

i use php to force the download of any file and this is my code


index.php

<a href="download.php?file_name=example.png"><button class="details_button_T">Télécharger</button></a>

download.php

$file= $_GET['file_name'];
if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit();
    }

the code works in all browsers only chrome displays an error : Double headers sent by the server

War es hilfreich?

Lösung

resolved its a little mistake

header('Content-Disposition: attachment; filename="'.basename($file).'"');

Andere Tipps

well is important to ensure that the propertie filename="NAME.xxx" must have doble coutes. inside de header.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top