-4

可能重复:
PHP 已发送的标头

我是 php 的初学者,我想创建一个下载按钮,但我收到了一个我不明白的错误。这是我的错误:

“警告:无法修改标头信息 - 标头已由 D:\Program Files\xampp\htdocs\FormsGenerator\download.php 中的(输出开始于 D:\Program Files\xampp\htdocs\FormsGenerator\index.php:125)发送11号线”

在第 125 行,我打开了 php 的标签来调用创建的函数。这是我的按钮功能代码:

<?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;
  }
}
?>

这是调用该类的创建对象:

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

有人能帮我吗?

4

1 回答 1

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

于 2013-01-03T17:23:59.530 回答