【php – 使用Silex下载文件】教程文章相关的互联网学习教程文章

phpheader函数实现文本文件下载的方法

header('Content-type: application/pdf');header('Content-Disposition: attachment; filename="downloaded.pdf"');readfile('original.pdf');?>对以上代码的说明: 第一句,只要改一下文档的类型就行,例如是下载txt文件,那就改为header(‘Content-type: application/txt);, 第二句,就是为你的下载文档起一个名字,如果是txt文件的话,可以改为header(‘Content-Disposition: attachment; filename=”downloaded.txt”‘); 第...

php强制下载指定类型文件的代码

//提示下载//site http://bbs.it-home.orgfunction downloadFile($file){/*Coded by Alessio Delmonti*/$file_name = $file;$mime = 'application/force-download';header('Pragma: public'); // requiredheader('Expires: 0'); // no cacheheader('Cache-Control: must-revalidate, post-check=0, pre-check=0');header('Cache-Control: private',false);header('Content-Type: '.$mime);header('Content-Disposition: attachment...

php实现文件下载的代码

php代码实现文件的下载,主要是header函数的应用,有需要的朋友,可以参考下。完整代码如下:PHP文件下载_程序员之家_bbs.it-home.org以上的代码主要是应用php header函数实现文件的下载,在php中有很多的文件内容类型可以这样操作,大家有空多研究下了。

php使用ftp下载文件的简单例子

为大家举一个php使用ftp函数下载文件的例子,练习php中ftp函数的用法,供初学的朋友参考。代码如下:

php强制下载mp3文件的实现代码

一些诸如 mp3 类型的文件,通常会在客户端浏览器中直接被播放或使用。如果你希望它们强制被下载,也没问题。本文介绍的这段代码,可以帮你实现。代码如下:有关php header信息的相关内容,请参考:php头部文件(header)信息。 您可能感兴趣的文章: php强制文件下载(避免文件或图片直接在浏览器中打开) php 强制文件下载的一段代码 php强制下载指定类型文件的代码 php 强制文件下载的实现代码一例 php强制性文件下载的函数

php实现浏览器点击下载TXT文档的代码

/*** txt文档点击下载* edit bbs.it-home.org*/$filename = '/path/'.$_GET['file'].'.txt'; //文件路径header("Content-Type: application/force-download");header("Content-Disposition: attachment; filename=".basename($filename));readfile($filename);?>说明: 第一个header函数设置Content-Type的值为application/force-download; 第二个header函数设置要下载的文件。注意这里的filename是不包含路径的文件名,filename的...

php超大文件下载及断点续传下载的实现代码

$sourceFile = "jbxue.tmp"; //要下载的临时文件名$outFile = "用户订单.xls"; //下载保存到客户端的文件名$file_extension = strtolower(substr(strrchr($sourceFile, "."), 1)); //获取文件扩展名//echo $sourceFile;if (!ereg("[tmp|txt|rar|pdf|doc]", $file_extension))exit ("非法资源下载");//检测文件是否存在if (!is_file($sourceFile)) {die("404 File not found!");}$len = filesize($sourceFile); //获取文件大小$file...

php安全下载大文件的实现代码

/*** 一般文件安全下载* edit bbs.it-home.org*/ $durl = 'file/phpcms2008_o2abf32efj883c91a.iso'; $filename = 'phpcms2008_o2abf32efj883c91a.iso'; $file = @fopen($durl, 'r'); header("Content-Type: application/octet-stream"); header("Accept-Ranges: bytes"); header("Accept-Length: ".filesize($durl)); header("Content-Disposition: attachment; filename=...

php跨浏览器下载文件时中文乱码问题的解决方法

/*** 解决跨浏览器下载文件,中文乱码的问题* edit bbs.it-home.org*/$ua = $_SERVER["HTTP_USER_AGENT"];$filename = "中文 文件名.txt";$encoded_filename = urlencode($filename);$encoded_filename = str_replace("+", "%20", $encoded_filename);header('Content-Type: application/octet-stream');if (preg_match("/MSIE/", $ua)) { header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');} els...

php实现文件下载(多种文件格式)的代码

/*** 文件下载* 多种文件格式,包括pdf、zip、gif、jpg、mpeg、word等。* edit bbs.it-home.org*/function dl_file($file){ //First, see if the file exists if (!is_file($file)) { die("404 File not found!"); } //Gather relevent info about file $len = filesize($file); $filename = basename($file); $file_extension = strtolower(substr(strrchr($filename,"."),1)); //This will set the Content...

phpreadfile函数下载文件并判断权限的代码示例

/*** header与readfile函数应用举例* 下载文件 判断权限* edit bbs.it-home.org*/ $file = get_file_address();// 文件的真实地址(支持url,不过不建议用url) if (file_exists($file)) {header('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename='.basename($file));header('Content-Transfer-Encoding: binary');header('Expires: 0'...

php实现上传与下载文件的一段代码

文件上传下载-bbs.it-home.org$dir = 'upload/';if(is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if($file!="." && $file!="..") { echo "".$file.""; } } closedir($dh);}}?>2,上传文件源代码 upload_file.php/*** 文件上传与下载* edit bbs.it-home.org*/ if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . ""; }...

一个不错的PHP文件下载类

/**** php文件下载类**范例: $download=new download('php,exe,html',false); if(!$download->downloadfile($filename)) { echo $download->geterrormsg();}* by bbs.it-home.org*/class download{var $debug=true;var $errormsg='';var $Filter=array();var $filename='';var $mineType='text/plain';var $xlq_filetype=array();function download($fileFilter='',$isdebug=true){$this->setFilter($fileFilter);$this->setdebug...

php实现文件下载功能的简单例子

nginx中文手册下载2,文件get.php,内容如下:/*** php实现文件下载* edit bbs.it-home.org*/if (!isset(GET["file"]) || !isset(GET["type"])) { print "no file selsect"; exit(); }$file = GET["file"].".".GET["type"]; if (@$fp = fopen($file,'r')){ header ("Content-type: octet/stream"); if (strstr(SERVER["HTTP_USER_AGENT"], "MSIE")){ header("Content-Disposition: filename=".mb_convert_encoding('nginx中文手...

一个简单的php文件下载函数

php文件下载_bbs.it-home.org set_time_limit(24*60*60); if (!isset($_POST['submit'])) die (); $destination_folder = './down/'; // 文件夹保存下载文件。必须以斜杠结尾 $url = $_POST['url']; $newfname = $destination_folder.basename($url); $file = fopen($url, "rb"); if ($file) { $newf = fopen($newfname, "wb"); if ($newf) while (!feof($file)) { ...