无法修改标头信息-标头已经发送了简单的解决方案


Cannot modify header information - headers already sent easy solution

嘿,伙计们,我只是想分享我为错误找到的解决方案:无法修改标头信息-标头已经发送。

假设一个代码的开头包含这样的标题:

<?php
header('Content-disposition: attachment; filename="video"');
header('Content-type: video/mp4');
$video = $_POST['$video'] ;
readfile("$video");
?>

出于某种原因,PHP不喜欢这样。要查看如何修复此视图,请在下面回答。

要修复这种类型的错误,您可以在代码中的<?php之前添加<? ob_start(); ?>,然后在代码末尾添加<? ob_flush(); ?>。>像这样:

<? ob_start(); ?>
<?php
header('Content-disposition: attachment; filename="video"');
header('Content-type: video/mp4');
$video = $_POST['$video'] ;
readfile("$video");
?>
<? ob_flush(); ?>

希望这能有所帮助。这是我发现的一个简单的解决方案,它对我和我所知道的其他人都很有效。