-
-6 1
-
昨天做那个用php下载文件的没懂对,在网上找的代码,在本地测试也没得啥子问题,服务器上面就是会报错,最后最后还是同事发我一段代码,嘿嘿,用上去对了,下面贴下这段代码,希望可以帮助爱好php学习的和php爱好者们。
PHP代码- $item=trim($_GET['fileName']).".txt";
- $abs_item='/usr/home/文件夹名称/文件夹名称/文件夹名称/'.$item;
- $browser='IE';
- header('Content-Type: '.(($browser=='IE' || $browser=='OPERA')?
- 'application/octetstream':'application/octet-stream'));
- header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
- header('Content-Transfer-Encoding: binary');
- header('Content-Length: '.filesize($abs_item));
- if($browser=='IE') {
- header('Content-Disposition: attachment; filename="'.$item.'"');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- } else {
- header('Content-Disposition: attachment; filename="'.$item.'"');
- header('Cache-Control: no-cache, must-revalidate');
- header('Pragma: no-cache');
- }
- @readfile($abs_item);
嘿嘿,希望对爱好php学习和php爱好者们有所帮助。
本文来源于php爱好者:php教程 —http://www.phplover.cn/
原文地址:http://www.phplover.cn/post/php-wenjianxiazai.html
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
1楼 无锡理财规划师
Post:2012-4-20 9:37:31