문제

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

도움이 되었습니까?

해결책

resolved its a little mistake

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top