PHP 中的 header() 函数

phpserver side programmingprogramming

header() 函数将原始 HTTP 标头发送到客户端。

语法

header(string,replace,resp_code)

参数

  • string − 要发送的标头字符串。

  • replace − 指示标头是否应替换前一个标头或添加第二个标头。

  • resp_code −它将 HTTP 响应代码强制为指定值

返回

header() 函数不返回任何内容。

示例

以下是保存生成的 PDF − 的示例

<?php
   header("Content-type:application/pdf");
   header("Content-Disposition:attachment;filename=output.pdf'");
   readfile("demo.pdf");
?>

下载的文件将是 “output.pdf”,而输入的是 “demo.pdf”。


相关文章