-3

Hey guys I just wanted to share this solution that I found for the error: Cannot modify header information - headers already sent.

Let's say one starts out with a code that contains headers like this:

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

For some reason PHP doesn't like this. To see how to fix this view answer below.

michael b
  • 149
  • 2
  • 4
  • 15

1 Answers1

-2

To fix this type of error you can add <? ob_start(); ?> before the <?php in your code and add <? ob_flush(); ?> at the end of your code after ?> Like this:

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

Hope this helps. This was a simple solution that I found and it works well for me and some others I know of.

michael b
  • 149
  • 2
  • 4
  • 15
  • `readfile("allyourpasswordsbelongtome.php");` – Lawrence Cherone Feb 09 '13 at 03:07
  • This answer is different than the other one, while the error is the same I wanted to show how there is a different solution to the question also. – michael b Feb 09 '13 at 03:10
  • The solution is plan your application and not to send output before setting headers, if you expect to set headers within the application flow then set headers before output. In your example your not going to want to send HTML along with your video file, this example may also cause you to run out of memory. – Lawrence Cherone Feb 09 '13 at 03:14
  • It's a non-solution because it won't remedy preceding whitespace or BOM issues, and sending binary data after buffering any premature output (which this code placemenet won't) would still corrupt the file format. -- Consider reading a few of the thousands of duplicates we have, see *Related* links right-hand. – mario Feb 09 '13 at 03:28