How to let users with required permission download a file via php?

前端 未结 5 1274
南旧
南旧 2021-01-03 00:27

I have a php file that acts as a gatekeeper for all the files I want people to download, who ahve sufficient privilages.

The code I use throw the file to the user i

5条回答
  •  独厮守ぢ
    2021-01-03 00:59

    Your method will cause memory problems, however it is possible to read and output the file in chunks. You will need to use flush() function after you echo each chunk of file. You can also make resuming downloads to work with a little more effort. Still this is an CPU hungry approach.

    The easier and better solution is to use "x-sendfile" header tag supported by both apache and lighttpd through their modules. All you'll have to do is just specify file name in your header, similar to this:

    header('X-Sendfile: filename-on-your-file-system');
    

    Link for lighttpd:

    http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file

提交回复
热议问题