|
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://bbs.it-home.org
* @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强制文件下载的代码,大多采用的是这样的方式。
QCMS 轻量级企业建站系统6.0.5
查看详情
QCMS企业建站系统是通过MVC架构开发的一套PHP轻量级系统,开源,小巧,易用,功能强大、可以自定义模块,容易二次开发,可以称得上是万能CMS系统,可用于企业站,文章站,图片站,下载站,你只要能想得到,就能做的到。 QCMS V6.0.0 主要功能描述特色说明: 简单易用的模板标签,是我们系统的核心组成部分,系统对SEO更友好,源代码全部开放,毫无保留! 1 内容模块有 ,新
0
|
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号