PHP output file on disk to browser

前端 未结 6 2070
轻奢々
轻奢々 2020-11-27 19:18

I want to serve an existing file to the browser in PHP. I\'ve seen examples about image/jpeg but that function seems to save a file to disk and you have to create a right si

6条回答
  •  攒了一身酷
    2020-11-27 20:12

    I use readfile() ( http://www.php.net/readfile )...

    But you have to make sure you set the right "Content-Type" with header() so the browser knows what to do with the file.

    You can also force the browser to download the file instead of trying to use a plug-in to display it (like for PDFs), I always found this to look a bit "hacky", but it is explained at the above link.

提交回复
热议问题