当前位置: 首页 > news >正文

php代码实例强制下载文件代码例子

php代码实例强制下载文件代码例子 

$filename = $_GET['file']; //Get the fileid from the URL // Query the file ID $query = sprintf("SELECT * FROM tableName WHERE id = '%s'",mysql_real_escape_string($filename)); $sql = mysql_query($query); if(mysql_num_rows($sql) > 0){ $row = mysql_fetch_array($sql); // Set some headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=".basename($row['FileName']).";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($row['FileName'])); @readfile($row['FileName']); exit(0); }else{ header("Location: /"); exit; }

php代码实例从网上下载文件代码例子 

set_time_limit(0); // Supports all file types // URL Here: $url = 'http://somsite.com/some_video.flv'; $pi = pathinfo($url); $ext = $pi['extension']; $name = $pi['filename']; // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL and pass it to the browser $opt = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); $saveFile = $name.'.'.$ext; if(preg_match("/[^0-9a-z._-]/i", $saveFile)) $saveFile = md5(microtime(true)).'.'.$ext; $handle = fopen($saveFile, 'wb'); fwrite($handle, $opt); fclose($handle);

http://www.lryc.cn/news/434259.html

相关文章:

  • Opencv中的直方图(3)直方图比较函数compareHist()的使用
  • 压力测试(内存、磁盘、网络、cpu)
  • ArcGIS JSAPI 高级教程 - ArcGIS Maps SDK for JavaScript - 原生代码实现动态扩散效果
  • Java 设计模式-代理模式
  • CTF靶场之BUUCTF介绍
  • 学会分析问题,画出分析图,解释问题过程,找出规律 ;整数数组分为左右2个部分,左边位奇数右边偶数
  • 数学基础 -- 线性代数正交多项式之勒让德多项式展开推导
  • Redis实战宝典:从主从模式、哨兵模式、集群模式一步步理解Redis集群
  • 828华为云征文|华为云Flexus X搭建借贷管理系统、二次开发借贷小程序 前端源码uniapp
  • 网站安全需求分析与安全保护工程
  • 后谷歌时代
  • 【CMake编译报错小复盘】CMAKE_CUDA_ARCHITECTURES,CMake version,GCC version问题
  • PMP--一、二、三模--分类--14.敏捷--技巧--DoDDoR
  • 【大数据】如何读取多个Excel文件并计算列数据的最大求和值
  • 【运维项目经历|043】上云项目-服务从物理机迁移到AWS云服务器
  • 【OpenCV】灰度化和二值化处理图像
  • 【生命不息,动出奇迹!】多系统萎缩患者必看
  • Verilog FPGA 仿真 控制任务
  • 在Vision Pro上实现五子棋、益智休闲游戏:一个可二次开发的框架
  • 使用 `Vitesse Uni App` 创建微信小程序并配置 uview-plus 和 alovajs
  • C#迭代器和接口IEnumerable,IEnumerator
  • 通信工程学习:什么是IP-CAN(IP连接接入网)
  • 使用 MongoDB 构建 AI:Patronus 如何自动进行大语言模型评估来增强对生成式 AI 的信心
  • openpose1.7.0编译 cuda12.2 cudnn 8.9.7.29 python3.7
  • 【华为OD流程】性格测试选项+注意事项
  • 《生物学教学》
  • C++ 标准库的典型内容
  • 【C++初阶】:C++入门,引用概念及其性质
  • Linux 中的 crontab 命令介绍以及使用
  • 单片机组成原理