php中使用head进行二进制流输出,让用户下载PDF等附件的方法
来源:互联网 发布:看视频网络不稳定 编辑:程序博客网 时间:2024/05/14 13:00
function downloadFile( $fullPath ){ // Must be fresh start if( headers_sent() ) die('Headers Sent'); // Required for some browsers if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // File Exists? if( file_exists($fullPath) ){ // Parse Info / Get Extension $fsize = filesize($fullPath); $path_parts = pathinfo($fullPath); $ext = strtolower($path_parts["extension"]); // Determine Content Type switch ($ext) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=\"".basename($fullPath)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".$fsize); ob_clean(); flush(); readfile( $fullPath ); } else die('File Not Found'); }
0 0
- php中使用head进行二进制流输出,让用户下载PDF等附件的方法
- php中使用head进行二进制流输出,让用户下载PDF等附件的方法
- servlet的方式下载二进制流PDF文件的方法
- php中对HTML字符进行源码输出的方法
- ios中的doc,pdf等附件的查看与下载问题
- 将任何变量的值进行二进制输出的方法
- 使用输出流解决在网页(JSP)中显示文档(PDF等)问题
- 使用Aspose.Pdf从PDF文件中获取个别的附件
- 使用solr创建 附件[word pdf txt等文件索引]
- PHP IE中下载附件问题
- 使用Aspose.Pdf在PDF文件中添加附件
- php让浏览器下载txt等类型的文件
- QT中进行debug输出和使用cout cin等的问题
- QT中进行debug输出和使用cout cin等的问题
- ios 使用NSURlSession 下载文件并且使用进度条进行文件下载进度读取以及打开附件(word,excel,ppt,pdf)显示
- php使浏览器直接下载pdf文件的方法
- php实现的下载附件,解决乱码
- 用Jsp输出Word,PDF等文件时进行的设置
- grep
- 马尔科夫链MCMC采样算法和LDA Gibbs Sampling
- Convert Sorted List to Binary Search Tree
- springMVC3学习(十)--注解式控制器
- javaScript中for...in用法
- php中使用head进行二进制流输出,让用户下载PDF等附件的方法
- springMVC3学习(十一)--文件上传CommonsMultipartFile
- Find Minimum in Rotated Sorted Array II
- SMA、SMB、SMC封装的二极管尺寸区分
- 【LeetCode】Reverse Linked List II
- springMVC IE9浏览器 jQuery的json数据拦截提示下载或者保存解决方法
- sql server 使用的几个问题解决 记下来
- springMVC3学习(十二)--文件上传优化CommonsMultipartResolver
- Cppcheck在vs上使用