php 强制文件下载的一段代码
发布时间:2015-10-13 编辑:jiaochengji.com
php实现文件强制下载的一段代码,进入指定页面后就弹出文件下载对话框,恰如梦中那突如其来的流星雨,相当地酷类,哈哈。
php 强制文件下载的代码。
<?php /** * Downloader * * @param $archivo * path al archivo * @param $downloadfilename * (null|string) el nombre que queres usar para el archivo que se va a descargar. * (si no lo especificas usa el nombre actual del archivo) * site http://www.jbxue.com * @return file stream */ function download_file($archivo, $downloadfilename = null) { if (file_exists($archivo)) { $downloadfilename = $downloadfilename !== null ? $downloadfilename : basename($archivo); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $downloadfilename); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($archivo)); ob_clean(); flush(); readfile($archivo); exit; } } ?>
以上代码,应用的是php头部文件(header)信息的处理方法,如果你曾留心,就会发现脚本学堂为大家收集的有关php强制文件下载的代码,大多采用的是这样的方式。
您可能感兴趣的文章:
php强制下载mp3文件的实现代码
PHP 强制下载文件示例代码
php 强制文件下载的一段代码
php 强制下载文件实例代码
php实现文件强制下载代码
php强制下载文件的代码(解决IE下中文文件名乱码问题)
php文件下载代码(多浏览器兼容、支持中文文件名)
PHP强制下载文件方法浅析
php强制文件下载的自定义函数代码
php文件下载(防止中文文件名乱码)的示例代码
上一篇:php强制下载指定类型文件的代码
下一篇:php 防注入的一段代码(过滤参数)
[关闭]