
一、PHP格式
<?php function downFileFromServer($showFileName, $downFilePath) { if(file_exists($downFilePath)) { if(is_readable($downFilePath)) { if(Trim($showFileName) == '') { $showFileName = 'undefined'; } ob_start(); ob_clean(); $file_size = filesize($downFilePath); header('Content-Encoding:none'); header('Cache-Control:private'); header('Content-Length:' . $file_size); header('Content-Disposition:attachment; filename=' . $showFileName); header('Content-Type:application/octet-stream'); readfile($downFilePath); ob_flush(); } } } //Sample downFileFromServer('a.abc', 'test.php'); ?>
二、ASP
<%
Function downFileFromServer(showFileName, downFilePath)
response.Clear
response.Buffer = true
Set ads = Server.CreateObject("ADODB.Stream")
ads.Type = 1
ads.Mode = 3
ads.Open
ads.LoadFromFile downFilePath
response.AddHeader("Content-Encoding", "None")
response.AddHeader("Cache-Control", "Private")
response.AddHeader("Content-Length", ads.Size)
response.AddHeader("Content-Disposition", "attachment; filename=" & showFileName)
response.ContentType = "application/octet-stream"
response.BinaryWrite(ads.Read(ads.Size))
ads.Close
Set ads = nothing
response.Flush
response.End
End Function
Call downFileFromServer("abc.test", Server.MapPath("test.asp"))
%>| 欢迎光临 PHP开发笔记 (http://phpvi.com/) | Powered by Discuz! 6.1.0 |