扫码关注官方订阅号
php或html网页,上面有个文件链接,点击它的时候,怎么样做是让这个文件打开,怎么样做是让它下载?就是出现那个下载对话框。
欢迎选择我的课程,让我们一起见证您的进步~~
这样是进行文件的下载:
function downloadfile($filename,$storage) { if(! is_file($storage)) exit('文件不存在!'); if(!$fp = fopen($storage, 'r')) exit('error'); header('Content-Type: application/octet-stream;charset=utf-8'); if(preg_match("/Trident/", $_SERVER["HTTP_USER_AGENT"])) { header('Content-Disposition: attachment; filename="'.utf8togbk($filename).'"'); } else { header('Content-Disposition: attachment; filename="'.$filename.'"'); } header('Content-Transfer-Encoding: binary'); while(! feof($fp)){ echo fread($fp,1025); } fclose($fp); }
打开文件应该是浏览器的行为吧?
通过php的header()方法,来修改html头部内容,来达到目的
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
这样是进行文件的下载:
打开文件应该是浏览器的行为吧?
通过php的header()方法,来修改html头部内容,来达到目的