PHP output file on disk to browser

前端 未结 6 2068
轻奢々
轻奢々 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条回答
  •  -上瘾入骨i
    2020-11-27 19:55

    There is fpassthru() that should do exactly what you need. See the manual entry to read about the following example:

    
    

    See here for all of PHP's filesystem functions.

    If it's a binary file you want to offer for download, you probably also want to send the right headers so the "Save as.." dialog pops up. See the 1st answer to this question for a good example on what headers to send.

提交回复
热议问题