首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(0) | 阅读2408次
PHP DOWNLOAD 下载 HEADER

PHP DOWNLOAD 下载 HEADER
PHP页面点击按钮之后生成一个CSV文件,然后提供用户下载,想做成直接下载,不用再生成一个链接,找了找资料,发现办法不少 www.shengfang.org

<?php
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="sf2.csv"');
readfile('sf2.csv');
?> www.shengfang.org

这个需要 HEADER放在最前面,需要作一个新的PHP文件

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Location:http://127.0.0.1/bill/admin/test/sf2.csv"); www.shengfang.org

这个比较简单,直接导向一个超级链接,让IE去处理。防制瀏覽器讀取Cache的Header用法

能在echo ,<html> ,session ,space后面出现的header:
内容:
问:我用header("location:文件名")导向这个文件,为什么总是提示我" Cannot add header information - headers already sent by "这个信息,请高手指点!在此表示感谢!
答:用這個代替header
header 調用之前,不能輸出http 頭。如果在之前輸出,echo ,<html> ,session ,space都會出現錯誤。
下面的function 無此限制 www.shengfang.org

function redirectURL($url, $seconds = 0){
/*can replace the head() function
at para $url   eg:$url='welcome dot php?sid=$sid|3';
redirectURL($url); //3 s, redirect $url
*/

if(!is_int($seconds))
$seconds=0;
$mta = "<META HTTP-EQUIV=REFRESH CONTENT=\"".$seconds.
";URL=".$url."\">";
echo $mta;
exit;
} www.shengfang.org


echo "sdffffffff";
redirectURL("http://127.0.0.1/bill/admin/test/sf2.rar");
exit();

If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

<?php www.shengfang.org
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
?>  www.shengfang.org

注: There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround. There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading to Service Pack 2 or later.

注: If safe mode is enabled the uid of the script is added to the realm part of the WWW-Authenticate header if you set this header (used for HTTP Authentication).

header www.shengfang.org
(PHP 3, PHP 4, PHP 5) www.shengfang.org

header -- Send a raw HTTP header
Description
void header ( string string [, bool replace [, int http_response_code]] )


header() is used to send raw HTTP headers. See the HTTP/1.1 specification for more information on HTTP headers.


字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/phpheaderdownload.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1133169102

2005年11月28日17:11星期一  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1790
在线: 13||用户: 2562 [列表]
今日:2140||到访:2671639
Rss:838441||评论:1584

最新日志

最新评论

友情链接

日历

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8