malformed header from script. Bad header=1: index.php

后端 未结 4 980
醉梦人生
醉梦人生 2021-01-18 20:22

I have a website which is a few years old now, it basically offers downloads.

Anyway since moving server people can not download files because its now giving a error

4条回答
  •  情歌与酒
    2021-01-18 20:59

    The problem is in

    header('Content-Length: ' . filesize($file) + 1);
    

    Dot is evaluated before plus so your code is string + 1, result is 1 and this causes that 1 is sent as header. Correct code should be

    header('Content-Length: ' . filesize($file));
    

    because according to this page http://www.php.net/manual/en/function.readfile.php no +1 is used. Other solution is

    header('Content-Length: ' . (filesize($file) + 1));
    

    which will work as you want.

提交回复
热议问题