//第一:
$url="/admin/upload/client.jpg";
$filename = "http://".$_SERVER['SERVER_NAME'].$Url;
//这样地址就变成http://loaclhost/admin/upload/client.jpgheader('Content-Disposition: attachment; filename=client.jpg');
header("Content-type: application/octetstream");
readfile($filename);
ob_flush();
//第二:这个要输出原类型,是变动的,不对应的话出错
header("Content-type: application/octetstream");
解决方案 »
- 想做一个在线考试系统,请教一下大家历史试卷存储方案
- Extjs htmleditor控件粘贴World文档内容问题,后台PHP过虑
- apache安装好了,怎样安装php?
- 用PHP能否实现手机扣费??
- 投票中这样的值怎么取
- 请大家给分析一下,关于这个网站:http://www.mnrc.com.cn
- 字符串操作问题?怎么判断$str中是否有某个字符串啊?
- [请问]php中用什么函数显式地将中文字符转换成unicode编码?
- 用php调用sql server的时候,为什么会出现如下错误?
- 在線等,關于stock和php傳送郵件的問題. 謝謝!
- 一个类在另一个类中定义的问题
- discuz的水印程序请教
读入一个文件并写入到输出缓冲。 返回从文件中读入的字节数。如果出错返回 FALSE 并且除非是以 @readfile() 形式调用,否则会显示错误信息。没有看到从缓冲区调出显示的file_get_contents呢?
$filename = "http://".$_SERVER['SERVER_NAME'].$Url;header('Content-Disposition: attachment; filename=client.jpg');
header("Content-type: text/html");
file_get_contents($filename);
这样是不报错的!但是文件下载下来是空的一张图片显示没有预览!是怎么回事!
$url="/admin/upload/client.jpg";
$filename = "http://".$_SERVER['SERVER_NAME'].$url;
//这样地址就变成http://loaclhost/admin/upload/client.jpgheader('Content-Disposition: attachment; filename=client.jpg');
header("Content-type: application/octetstream");
readfile($filename);
?>
我的是Content-type: text/html
不是Content-type: application/octetstream
我也改了!
readfile()我也改成file_get_contents()文件可以下载了!但是下载后文件打开是空白!
readfile()我也改成file_get_contents() 后就不会有乱码出现了!现在就是下载后文件无法显示。PHP还有其他下载方式吗?
define("MPDEVELOP",true);
include_once("../config.php");
include_once(ROOT."/common/mysql.php");
include_once(ROOT."/common/functions.php");
include_once(ROOT."/common/global.php");
$db = new db();
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
$db->select_db($dbname);if(!is_numeric($id))exit;
$query = $db->query("select * from messagefiles where `id` = '$id'");
$res = $db->fetch_array($query);
$filename = $res['filename'];
$showname = $res['showname'];
$file = fopen(MESSAGEFILESDIR.$filename,"r");
if (!$file)
{
echo "文件找不到";
}
else
{
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=" .$showname);
while (!feof ($file))
{
echo fread($file,50000);
}
fclose ($file);
}
?>
这里的50000代表什么含义!我看是length,是什么长度。
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=client.jpg");
header("Content-Transfer-Encoding: binary");
readfile($filename);
这里的50000代表什么含义!我看是length,是什么长度。
---------------------
这个50000指每次读取的字节数,直到读取到eof(文件末尾)
你也可以写成4096