一、网页请求和响应的过程
请求:
1. HTTP 1.1 协议 版本
2. 头信息,请求的ip,其他
3. 你请求的表单信息, 你提交给服务器的信息 http://localhost/one.php?aa=bbb&ccc=dd
响应:
1. 状态 200 ok 404 页面没找到
2. 响应头信息, header();在头的前面不能有非头信息数据的输出,否则会报错。
3. 数据发送
二、具体文件下载的一些PHP代码
1、header发送的数据及注意事项
<?php
header("Content-Type:text/html;charset=utf-8");//如果你写文件的编码是gb2312,而发送utf-8的编码,在网页则会显示乱码
echo '<h1>wwwwwwwwwwwwww </h1>';
//header("Location:http://www.baidu.com"); //文件头不能有非头信息输出
echo '<script>window.location="two.html"</script>';
echo "这是一个中国字";
?>
2、指定文件发送的数据
<?php
header("Content-Type:image/gif");//指定发送头部的数据类型
header('Content-Disposition: attachment; filename="logo3333.gif"'); //指定文件的名字
header('Content-Length:'.filesize("logo.gif")); //指定文件发送的大小,一般会自动检测
readfile("logo.gif");//读取并发送
?>
相关文章:
猜你喜欢
-
2021-05-21
-
2021-10-25
-
2021-08-28
-
2022-02-23
-
2022-02-18
-
2021-08-27
相关资源
-
下载
2023-01-02
-
下载
2021-06-06
-
下载
2022-12-19
-
下载
2021-06-23