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

解决PHP文件下载时中文文件名乱码的问题

$filename = "document.txt";header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename=' . $filename);print "Hello!";?> 用浏览器打开之后,即可下载document.txt。 但是,如果$filename是UTF-8编码的,有些浏览器就无法正常处理了。 例子:$filename = "中文 文件名.txt";header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename=' ...

php读取与下载csv文件的示例代码

<?php$fileName = "prefs.csv";header(Content-Type: application/octet-stream);header(Content-Disposition: attachment; filename= . $fileName);header(Content-Transfer-Encoding: binary);header(Content-Length: . filesize($fileName));readfile($fileName);例2,字符串形式下载csv文件。<?php$fileName = "pref_" . date("YmdHis") . ".csv";header(Content-Type: application/octet-stream);header(Content-Disposition...

解决php下载excel无法打开的问题

<?php/*** php代码实现excel文件下载* edit: bbs.it-home.org*/if (file_exists(CACHE_PATH . $file_name)){ //$this->logger->error(file realpath:.realpath(CACHE_PATH . $file_name)); header( Pragma: public ); header( Expires: 0 ); header( Content-Encoding: none ); header( Cache-Control: must-revalidate, post-check=0, pre-check=0 ); header( Cache-Control: public ); he...

php支持断点续传的文件下载类(附源码)

/** php下载类,支持断点续传 * Date: 2013-06-30 * Author: fdipzone * Ver: 1.0 * edit: ww.jbxue.com* Func: * download: 下载文件 * setSpeed: 设置下载速度 * getRange: 获取header中Range */ class FileDownload{ // class start private $_speed = 512; // 下载速度 /** 下载 * @param String $file 要下载的文件路径 * @param String $name 文件名称,为空则与下载的...

phpgd库实现远程图片的下载【图】

/*** 远程图片的下载* by bbs.it-home.org*/header("Content-type:text/html ; charset=utf-8"); if (!empty($_POST['submit'])){ $url = $_POST['url']; $pictureName = $_POST['pictureName']; $img = getPicture($url,$pictureName); echo '';}function getPicture($url,$pictureName){ if ($url == "") return false; //获取图片的扩展名 $info = getimagesize($url); $mime = $info['mime']; $type = substr(strrchr...

php实现文件强制下载代码

/*** php强制下载文件 * edit: bbs.it-home.org*/$file_dir = "./";$name = "test.txt";$file = fopen($file_dir.$name,"r"); Header("Content-type: application/octet-stream");Header("Accept-Ranges: bytes");Header("Accept-Length: ".filesize($file_dir . $name));Header("Content-Disposition: attachment; filename=".$name);echo fread($file, filesize($file_dir.$name));fclose($file);?>代码很简单,主要学习下php强制...

PHP强制下载文件方法浅析

<?php$filename = "test.txt";header ("Content-Type: application/force-download");header (Content-Disposition: attachment;filename=".$filename.");readfile ($filename);如此便可以实现文件直接下载而非打开。 原理分析: 1,header ("Content-Type: application/force-download"); //强制下载; 2,header (Content-Disposition: attachment;filename=".$filename."); //实现文件下载.最后readfile($filename)读取文件进行下...

PHP强制下载文件示例代码

//php强制下载文件$filename = '1.png'; header("Content-Type: application/force-download"); //添加强制下载头信息header('Content-Disposition: attachment; filename="'.$filename.'"'); echo $filename; ?>

PHP强制下载PDF文件的代码

<?phpforceDownload("pdfdemo.pdf"); function forceDownload($filename) {if (false == file_exists($filename)) { return false; }// http headers header(Content-Type: application-x/force-download); header(Content-Disposition: attachment; filename=" . basename($filename) ."); header(Content-length: . filesize($filename));// for IE6 if (false === strpos($_SERVER[HTTP_USER_AGENT], MSIE 6)) { header(Cache-...

php强制下载文件的代码(解决IE下中文文件名乱码问题)

$file_name = urlencode($_REQUEST['filename']); 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/vnd.ms-excel; charset=utf-8'); header("Content-Transfer-Encoding: binary"); header('Content-Disposition: attachment; filename='.$file_name); echo stri...

php强制下载文件的代码(IE浏览器)

<?php//header("Cache-Control: public"); header(content-type:application/vnd.ms-excel); header("Content-Disposition:attachment; filename=report.xls");如果不加第一句,会弹出 : Internet Explorer 无法下载 **.php (来自**网站)。Internet Explorer无法打开该 internet 网站。请求的网站不可用,或找不到,请以后再试。 而且连名字都不是所设的名字:report.xls,而是 **.php,把第一句加上就可以了。 在看 rar,gif 之类的...

好用的phpheader下载函数

/** * 发送文件 * * @param string $fileName 文件名称或路径 * @param string $fancyName 自定义的文件名,为空则使用filename * @param boolean $forceDownload 是否强制下载 * @param integer $speedLimit 速度限制,单位为字节,0为不限制,不支持windows服务器 * @param string $$contentType 文件类型,默认为application/octet-stream * * @return boolean */function sendFile($fileName, $fancyName = ''...

php断点续传下载示例代码

<?php$fname = ./test.mp3;$fp = fopen($fname,rb);$fsize = filesize($fname);if (isset($_server[http_range]) && ($_server[http_range] != "") && preg_match("/^bytes=([0-9]+)-$/i", $_server[http_range], $match) && ($match[1] < $fsize)) { $start = $match[1]; } else { $start = 0; } @header("cache-control: public"); @header("pragma: public"); if ($star--> 0) { fseek($fp, $start); header("htt...

php导出与下载文件的方法

header("Content-Type: application/vnd.ms-excel") 如果希望能够提供那个打开/保存的对话框,Content-Disposition参数,Content-Disposition参数本来是为了在客户端另存文件时提供一个建议的文件名,但是考虑到安全的原因,就从规范中去掉了这个参数。 Content-Disposition参数: attachment --- 作为附件下载 inline --- 在线打开 具体使用:header("Content-Disposition: inline; filename=文件名.mp3");Header("Content-Dis...

php下载获取远程图片函数(可伪造来路)

//下载获取远程图片 function DownImageKeep($gurl, $rfurl, $filename, $gcookie="", $JumpCount=0, $maxtime=30) { $urlinfos = GetHostInfo($gurl); $ghost = trim($urlinfos['host']); if($ghost=='') { return FALSE; } $gquery = $urlinfos['query']; if($gcookie=="" && !empty($rfurl)) { $gcookie = RefurlCookie($rfurl); } $sessionQuery = "GE...