<%
'filepath 文件地址
'file_Rname 显示给客户的文件名function downloadFile(filepath,file_Rname)
'on error resume nextresponse.buffer=trueSet fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filepath)
Set S=CreateObject("Adodb.Stream")
S.Mode=3
S.Type=1
S.Open
S.LoadFromFile(filepath)'开始下载
if Err.Number>0 then
Response.Status="404"
else
Response.AddHeader "Content-Disposition","attachment; filename=" & file_Rname Response.CharSet = "UTF-8"
'application/download_only 使浏览器无法辨别文件类型,防止在浏览器内直接打开
Response.ContentType="application/download_only"
Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)
if Range="" then
Response.BinaryWrite(S.Read)
else
S.position=Clng(Split(Range,"-")(0))
'支持断点续传
Response.BinaryWrite(S.Read)
End ifResponse.Endend function
%>实现只下载的 asp代码
'filepath 文件地址
'file_Rname 显示给客户的文件名function downloadFile(filepath,file_Rname)
'on error resume nextresponse.buffer=trueSet fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filepath)
Set S=CreateObject("Adodb.Stream")
S.Mode=3
S.Type=1
S.Open
S.LoadFromFile(filepath)'开始下载
if Err.Number>0 then
Response.Status="404"
else
Response.AddHeader "Content-Disposition","attachment; filename=" & file_Rname Response.CharSet = "UTF-8"
'application/download_only 使浏览器无法辨别文件类型,防止在浏览器内直接打开
Response.ContentType="application/download_only"
Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)
if Range="" then
Response.BinaryWrite(S.Read)
else
S.position=Clng(Split(Range,"-")(0))
'支持断点续传
Response.BinaryWrite(S.Read)
End ifResponse.Endend function
%>实现只下载的 asp代码
解决方案 »
- 求教word文档格式成网页填写并打印出相同效果的实现
- 十万火急!求大神们教我如何在本机上调试该PHP网站!在线等。。。
- 这段代码怎么拉?怎么显示不出图片呢?
- php二维数组如何正确赋值?
- 正则表达式问题 在线等
- 关于删除和下载的一个问题。。
- 我想要学习PHP了,请教一下,用哪个软件?用什么书?我想开发一个网站.
- 加急:执行一个php连接mysql的语句结果提示;Fatal error: Call to undefined function: mysql_connect()
- 帮我看看这是为什么?解决就加分,50分奉上!!!!
- 这个问题是为什么呢?
- 求助,Premature end of script headers: php/php.exe 如何解决
- 我的服务器没有调试信息怎么办?
<?
@session_start();
error_reporting('0');
if(!isset($File))$File = "temp.txt";$Path = "./upfiles/";
$filestail=strrchr($File,".");
$namestr = str_replace($filestail,"",$File);
$strs = split("-",$namestr);
$Path .= "D".$strs[2]."/";
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=$File");
header("Content-Description: PHP Generated Data");
readfile($Path.$File);?>
{
$upload_dir= "../".$_GET['path'];
$upload_file = $_GET['filename'];
$fp = fopen($upload_dir.$upload_file,"r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($upload_dir.$upload_file));
Header("Content-Disposition: attachment; filename=" . $upload_file);
echo fread($fp,filesize($upload_dir . $upload_file));
fclose($fp);
}
我对php接触没有几天。。 sandyuk(冰の沙隆) 和bonniewater(陪你去看海) 两位大侠能否详细解释该怎么做,该放到哪里,我的下载链接该怎么写阿?
Warning: Cannot add header information - headers already sent by (output started at c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\grid.php:7) in c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\grid.php on line 8
你把这个函数写到一个文件download.php中
download.php
<?php
function download()
{
$upload_dir= "../".$_GET['path'];
$upload_file = $_GET['filename'];
$fp = fopen($upload_dir.$upload_file,"r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($upload_dir.$upload_file));
Header("Content-Disposition: attachment; filename=" . $upload_file);
echo fread($fp,filesize($upload_dir . $upload_file));
fclose($fp);
}
download();
?>
我写了之后会报错:这是什么原因,是我的设置问题嘛?
错误信息如下:
Warning: Cannot add header information - headers already sent by (output started at c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php:5) in c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php on line 13Warning: Cannot add header information - headers already sent by (output started at c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php:5) in c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php on line 14Warning: Cannot add header information - headers already sent by (output started at c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php:5) in c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php on line 15Warning: Cannot add header information - headers already sent by (output started at c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php:5) in c:\Program Files\Apache Group\Apache\htdocs\hcycom\host\download.php on line 16