//第一:
$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");
读入一个文件并写入到输出缓冲。 返回从文件中读入的字节数。如果出错返回 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