PHP下载保存文件
来源:互联网 发布:java订单管理系统源码 编辑:程序博客网 时间:2024/06/06 09:57
以下是对php下载保存文件保存到本地的两种实现方法进行了介绍
第一种:
<?php function downfile(){ $filename=realpath("resume.html"); //文件名 $date=date("Ymd-H:i:m"); Header( "Content-type: application/octet-stream "); Header( "Accept-Ranges: bytes "); Header( "Accept-Length: " .filesize($filename)); header( "Content-Disposition: attachment; filename= {$date}.doc"); echo file_get_contents($filename); readfile($filename); }downfile();?>
或
<?php function downfile($fileurl){ ob_start(); $filename=$fileurl; $date=date("Ymd-H:i:m"); header( "Content-type: application/octet-stream "); header( "Accept-Ranges: bytes "); header( "Content-Disposition: attachment; filename= {$date}.doc"); $size=readfile($filename); header( "Accept-Length: " .$size);}$url="url地址";downfile($url);?>
第二种:
<?php function downfile($fileurl){$filename=$fileurl;$file = fopen($filename, "rb"); Header( "Content-type: application/octet-stream "); Header( "Accept-Ranges: bytes "); Header( "Content-Disposition: attachment; filename= 4.doc"); $contents = "";while (!feof($file)) { $contents .= fread($file, 8192);}echo $contents;fclose($file); }$url="url地址";downfile($url);?>
PHP实现下载文件的两种方法
方法一:
<?php/*** 下载文件* header函数**/header('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename='.basename($filepath));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($filepath));readfile($file_path);?>`这里写代码片`
了解php中header函数的用法。
方法二:
<?php//文件下载//readfile$fileinfo = pathinfo($filename);header('Content-type: application/x-'.$fileinfo['extension']);header('Content-Disposition: attachment; filename='.$fileinfo['basename']);header('Content-Length: '.filesize($filename));readfile($thefile);exit();?>
http://www.jb51.net/article/40485.htm
0 0
- PHP下载保存文件
- php 下载保存文件保存到本地
- PHP 下载保存文件到本地
- php下载文件并保存到指定文件夹
- php 下载保存文件保存到本地的两种实现方法
- PHP 异地保存文件
- 关于文件保存 php
- php 保存文件
- php保存文件
- PHP 上传保存文件
- 保存yum下载的文件
- android文件下载与保存
- android 文件下载和保存
- 客户端下载或保存文件
- 利用 jsoup 下载保存文件
- Android 文件下载保存读取
- 在ecplise每次新建一个php文件或者保存一个PHP文件的时候总是提示下载...
- php利用header函数实现文件下载时直接提示保存
- Java 8:HashMap的性能提升
- ubuntu安装软件终端变成 package configuration 下面有ok键但是点不住
- 【JavaScript】开发谷歌浏览器插件
- 子树
- 网页设计大赛第十二天
- PHP下载保存文件
- UVa 11775 Unique Story
- UML学习:机房收费系统-图集(协作,顺序,部署,构件)
- 写文件
- Linux进程的五个段
- 安装HAXM模拟器加速器:failed to open driver
- bzoj 3689 异或之
- 今天第一次在杭电做题,虽然做的题比较简单,出错也依旧多,花费了很长时间,不过很开心,还学到一些知识,继续努力
- Linux下自定义虚拟串口驱动