修改文本编码
- header("Content-Type: text/html;charset=utf-8");
重定向
- // header("Location:a.php");
- header("Location:http://www.126.com");
多少秒后跳转
- header("Refresh:5;url='http://www.126.com'");
缓存
- //不启用缓存 多个配置 适配不同的浏览器
- header("Expires:-1");
- header("Cache-Control:no-cache");
- header("Pragma:no-cache");
文件下载
- <?php
- //在此页面中不能调用echo等方法在页面显示内容,否则下载的内容就是错误的
- $str = "我的.jpg";
- //中文的文件名 php文件系统不认,须转换
- $str=iconv('UTF-8','GB2312',$str);
- if(!file_exists($str)){
- echo "找不到文件:".$str;
- return;
- }
- $fp = fopen($str, "r");
- $file_size = filesize($str);
- while (! feof($fp)) {
- $read = fread($fp, 1024);
- echo $read;
- }
- fclose($fp);
- // 说明返回的是文件
- header("Content-Type:application/octet-stream");
- // 按字节大小返回
- header("Accept-Range:bytes");
- // 文件有多大
- header("Content-Length:" . $file_size);
- // 文件名 弹出框的名称
- header("Content-Disposition:attachment; filename=" . $str);
- ?>