PHP强制文件下载,而不是在新的选项卡/窗口中打开
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP强制文件下载,而不是在新的选项卡/窗口中打开相关的知识,希望对你有一定的参考价值。
provide file via URL var, and script will grab it & force download. Take a look at code, and add some of your filetypes if required
$file_name = $_GET['file']; // make sure it's a file before doing anything! { /* Do any processing you'd like here: 1. Increment a counter 2. Do something with the DB 3. Check user permissions 4. Anything you want! */ // required for IE // get the file mime type using the file extension { case 'pdf': $mime = 'application/pdf'; break; case 'zip': $mime = 'application/zip'; break; case 'jpeg': case 'jpg': $mime = 'image/jpg'; break; default: $mime = 'application/force-download'; } }
以上是关于PHP强制文件下载,而不是在新的选项卡/窗口中打开的主要内容,如果未能解决你的问题,请参考以下文章
window.open(url, windowname, opts) 在新选项卡中打开,而不是在 Firefox 中打开新窗口
在新选项卡/窗口中打开链接而不丢失当前 JSF 页面的视图范围