-4

Possible Duplicate:
Headers already sent by PHP

I am a begginner in php and I want to create an download button but I received an error that i don't understand. This is my error:

"Warning: Cannot modify header information - headers already sent by (output started at D:\Program Files\xampp\htdocs\FormsGenerator\index.php:125) in D:\Program Files\xampp\htdocs\FormsGenerator\download.php on line 11"

On 125 row I had open the tag for php to call the functions created. This is my cod for button functionality:

<?php
class fileDownload{
  function fileDownload(){
      $core_path = dirname(__FILE__);
      $file_path = "{$core_path}/file/form.html";
      $file_info = array(
            'name' => basename($file_path),
            'size' => filesize($file_path)
        );

      header('Content-Type: application/html');
      header('Content-Description: File Transfer');
      header('Content-Disposition: attachment; filename="'.$file_info['name'].'"');
      header('Content-Lenght: '.$file_info['size']);
      $file = fopen($file_path, 'rb');

      while(!feof($file)){
        echo fread($file, 256);
      }

      fclose($file);
      return;
  }
}
?>

And here is the created object that calls the class:

if(isset($_GET['download'])){
       include 'download.php';
        $download = new fileDownload();
}

Can someone help me?

Community
  • 1
  • 1
Nistor Alexandru
  • 5,309
  • 9
  • 46
  • 71
  • 1
    Look for whitespace like a blank line before or after `` – Michael Berkowski Jan 03 '13 at 17:23
  • Look for any output being sent before the attachment is being sent to the browser. Also, It seems you have made an error here: `header('Content-Lenght: '.$file_info['size']);` (Should be content-length) – user1909426 Jan 03 '13 at 17:25

1 Answers1

1

Before calling header function you cannot send any output to browser, not even from simple HTML code that you have above your php. That must be the reason

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95