The header () function sends the original HTTP header to the client.
It is important to recognize that the header () function must be invoked before any actual output is sent (in PHP Tutorial 4 and later, you can use output caching to solve this problem):
<?php
Error results
Output already exists before calling header ()
Header (' location:http://www.111cn.net/');
?> syntax
Header (string,replace,http_response_code) parameter description
String required. Specify the header string to send.
Replace is optional. Indicates whether the header replaces the previous header, or adds a second header.
The default is true (replace). False (allows multiple headers of the same type).
Http_response_code Optional. Forces the HTTP response code to the specified value. (PHP 4 and later available)
<?php
function Downfile ()
{
$filename =realpath ("resume.html");
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
Header ("Accept-length:". FileSize ($filename));
Header ("content-disposition:attachment; Filename= 4.html ");
Echo file_get_contents ($filename);
ReadFile ($filename);
}
Downfile ();
?>
<?php
function Downfile ($fileurl)
{
$filename = $fileurl;
$file = fopen ($filename, "RB");
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
Header ("content-disposition:attachment; Filename= 4.doc ");
$contents = "";
while (!feof ($file)) {
$contents. = Fread ($file, 8192);
}
Echo $contents;
Fclose ($file);
}
$url =$_request[' url '];
$url = "Http://www.111cn.net";
Downfile ($url);
?>