php下载文件,添加响应头

//下载,添加响应头信息
header(‘Content-type:application/octet-stream‘);
header(‘Content-Disposition:attachment;filename="‘.basename($file).‘"‘);
header(‘Content-Length:‘.filesize($file));
readfile($file);

时间: 2024-12-08 15:50:01

php下载文件,添加响应头的相关文章

正确处理下载文件时HTTP头的编码问题(Content-Disposition)

转自:https://blog.robotshell.org/2012/deal-with-http-header-encoding-for-file-download/ 最近在做项目时遇到了一个 case :需要实现一个强制下载功能(即强制弹出下载对话框,阻止浏览器尝试解析显示某些文件格式),并且文件名必须保持和用户之前上传时相同(可能包含非 ASCII 字符). 前一个需求很容易实现:使用 HTTP Header 的 Content-Disposition: attachment 即可,还可

给VS类文件添加默认头注释

找到类文件所在路径:C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\2052\Class 1.打开Class.cs文件在文件头部插入以下代码: 1 #region 文件注释 2 /* =============================================== 3 * 功能描述:$safeitemrootname$ 4 * 创 建 人:王

【转】正确处理浏览器在下载文件时HTTP头的编码问题(Content-Disposition)

最近在做项目时遇到了一个 case :需要实现一个强制在浏览器中的下载功能(即强制让浏览器弹出下载对话框),并且文件名必须保持和用户之前上传时相同(可能包含非 ASCII 字符). 前一个需求很容易实现:使用 HTTP Header 的 Content-Disposition: attachment 即可,还可以配合 Content-Type: application/octet-stream 来确保万无一失.而后一个需求就比较蛋疼了,牵扯到 Header 的编码问题(文件名是作为 filena

php下载文件添加header响应头

header('Content-type:application/octet-stream'); header('Content-Disposition:attachment;filename="'.basename($file).'"'); header('Content-Length:'.filesize($file)); readfile($file); 原文地址:https://www.cnblogs.com/jielin/p/10203140.html

nodejs 服务端添加相应头Access-Control-Allow-Origin

重点在这句:res.setHeader("Access-Control-Allow-Origin", "*"); var http = require("http"); http.createServer(function (req, res) { // 添加响应头 res.setHeader("Access-Control-Allow-Origin", "*"); // 获取请求路径 var pathna

将一个文件作为下载的形式打开【下载文件】,添加报文头context.Response.AddHeader("Content-disposition", "attachment; filename="

<1> HTMLPage1.htm页 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <a href="下载Handler1.ashx">下载</a> </body> </html> 下载Handler1.ashx.cs

Servlet下载文件和http响应

下载文件等: 1.得到公共的内容ServletContext sc = this.getServletContext(); 2.在链接名字后面加个? 一个参数?参数1=值 两个参数?参数1=值&参数2=值 <a href="DownLoadServlet?fileName=正则表达式.html">下载正则表达式.html</a> 3.得到参数   String fileName = request.getParameter("fileName&

JavaWeb学习记录(一)——response响应头之缓存设置与下载功能的实现

一.HTTP中常用响应头 Location: http://www.it315.org/index.jsp Server:apache tomcat Content-Encoding: gzip Content-Length: 80 Content-Language: zh-cn Content-Type: text/html; charset=GB2312 Last-Modified: Tue, 11 Jul 2000 18:23:51 GMT Refresh: 1;url=http://ww

header头 下载文件 参数详解

header("Pragma: public"); //1 header("Expires: 0"); //2 header("Cache-Control:must-revalidate, post-check=0, pre-check=0");//3 header("Content-Type:application/force-download");//4 header("Content-Type:applicat