PHP: How to make browser to download file on click

后端 未结 2 410
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 10:46

PHP Beginner. File uploading is successful but my browser doesn\'t download the files, instead it reads the file. So i referred other threads and found below code which is not w

2条回答
  •  执念已碎
    2021-01-29 11:19

    You have to use two separate files.

    In link page, you can output a HTML like this:

    Download file 1
    Download file 2
    Download file 3
    (...)
    

    You can use a

    , if you prefer.

    Then, in download.php:

    1. Select appropriate file using GET/POST parameter ($_GET['file'] in above example);

    2. send appropriate headers (like in your original code);

    3. echo your file (you can use readfile);

    4. Mandatory: no additional output in this script! Even a single additional space will corrupt downloaded file.

提交回复
热议问题