PHP Force Download Causing 0 Byte Files

后端 未结 8 1142
清歌不尽
清歌不尽 2020-12-10 16:11

I\'m trying to force download files from my web server using PHP. I\'m not a pro in PHP but I just can\'t seem to get around the problem of files downloading in 0 bytes in s

8条回答
  •  半阙折子戏
    2020-12-10 17:02

    The trick is to check with file_exists to confirm the correct path. The big confusion is that for PHP paths you don't need to start with '/' to say your website start path.

     '/folder/file.ext'  #bad, needs to know the real full path
    

    in php / is the website main path already, you don't need to mention it. Just:

     'folder/file.ext'   #relative to the / website
    

    This will work with file_exists, header filename, readfile, etc...

提交回复
热议问题