Invalid header from script. Bad title = 1: index.php

I have a website that is now several years old, it mainly offers downloads.

In any case, since moving the server cannot load files, because now it gives an error of 500 errors, and in the log files it brings this error:

Invalid header from script. Bad title = 1: index.php

The only code that is related to this that I see anyway is this:

// Echo $productOptionDetails->file;                
$file = DOWNLOAD_FOLDER. '/'. $productOptionDetailEntity->file;

    if (file_exists($file)) {

        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file) + 1);
        ob_clean();
        flush();
        readfile($file);
        exit;
    }

Now, if I just output:

// Echo $productOptionDetails->file;                
$file = DOWNLOAD_FOLDER. '/'. $productOptionDetailEntity->file;

if (file_exists($file)) {
   readfile($file);
   exit;
}

It outputs a lot of ciphertext, so it is clearly reading something.

What I read is that the headers are incorrect, but after reading the content downloads on php.net, as well as on other websites, it looks fine.

Can anyone scream why I get these errors?

thank

+4
4

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

Dot , + 1, 1, , 1 .

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

http://www.php.net/manual/en/function.readfile.php +1. -

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

, .

+7

, , , , , echo. , , echo .

echo, HTML tags .

, , - .

0

, .

, php , , UTF-8 ( ).

, -, , script.

, ob_clean(); (); .

0

As far as I understand from the code is flush()not required. Also, instead of

ob_clean();
flush();

just use ob_end_clean()to clear any buffered code.

And you said that you are moving servers, and now it does not work, so you also changed the PHP settings or version?

If so, than publish the PHP configuration for output_buffering.

0
source

Source: https://habr.com/ru/post/1535573/


All Articles