<%@ Language=VBScript %>
<%   Response.Buffer=true
   
   '取得要下载的文件,如果不为空。就下载
   dim url,trueurl
   
   fname=request("file")
   trueurl=request("Filepath")
   'if fname<>"" then
     ' trueurl=server.MapPath(fname) 
   'else
      'Response.end    
   'end if
   response.write trueurl
   set objFso=server.CreateObject("scripting.filesystemobject")
   if objFso.FileExists(trueurl) then 
   set fn=objFso.GetFile(trueurl)
   flsize=fn.size
   flname=fn.name
   set fn=nothing
   set objFso=nothing   set objStream=server.CreateObject("adodb.stream")
   objStream.Open 
   objStream.Type=1
   objStream.LoadFromFile trueurl
      
  
ContentType = "application/octet-stream"
  
  
   Response.AddHeader "Content-Disposition", "attachment; filename=" &request("file")''''&lcase(Right(fName, 4))'flname
   Response.AddHeader "Content-Length", flsize
   Response.CharSet="gb2312"
   Response.ContentType=ContentType
    'response.write("aa")
  
   Response.BinaryWrite objStream.Read   
  
   Response.Flush 
   'Response.Clear()
   objStream.Close
   set objStream=nothing   
   else
      response.write "此文件不存在,可能已经被删除!"
  Set objFso = nothing
      response.write "<script LANGUAGE='JavaScript'><!-- setTimeout(window.close, 5000);//--> </script>"
   end if
      response.write "<script LANGUAGE='JavaScript'><!-- setTimeout(window.close, 5000);//--> </script>"
      response.end
%>

解决方案 »

  1.   

    不好意思.贴错了.贴到asp文件去了...
    再来...
    <?php
    /*
    本程序是提供下载的功能.
    */
    $file_Down=$_GET['downloadfile'];
    $GLOBALS["filename"]=$_GET['filename'];
    download_file($file_Down); function download_file($path_file){
    ini_set('max_execution_time', 600);
         if (!file_exists($path_file)) {
             die("Error: File(".$path_file.") does not exist");
         }
         if (!($fp = fopen($path_file, "r"))) {
             die("Error: Cannot open the file(".$path_file.")");
         }
         fclose($fp);
         if (($content_length = filesize($path_file)) == 0) {
             die("Error: File size is 0.(".$path_file.")");
         }
    /*
         header("Content-Disposition: inline; filename=\"".basename($path_file)."\"");
         header("Content-Length: ".$content_length);
         header("Content-Type: application/file");
    */
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/x-php");
    header("Content-Disposition: attachment; filename=".$GLOBALS["filename"].";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($path_file));
    header("Content-type:application/octet-stream");     if (!readfile($path_file)) {
             die("Cannot read the file(".$path_file.")");
         }
         ini_set('max_execution_time', 30);
    }/*
    $file_name=$_GET['downloadfile'];
    echo $file_name;
    //$file_dir="/home/data/Music/";
    if(!file_exists($file_name))
    {echo "can not found file";
    exit;
    }
    else
    {
    Header("Content-Disposition:attachment;filename=".$file_name);
    Header("Accept-Length:".filesize($file_name));
    Header("Content-type:application/octet-stream");
    $file=fopen($file_name,"rb");
    echo fread($file,filesize($file_name));
    fclose($file);
    exit;
    }
    */
    ?>
      

  2.   

    如果客户端浏览器是ie系列:header( 'Content-Disposition: inline; filename="' . $file_name . '"' );
    header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
    header( 'Pragma: public' );如果客户端浏览器是非ie系列:header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
    header( 'Pragma: no-cache' );上面的$file_name是输出文件的路径,注意在header前不能有其它的输出。最后加上这句,输出文件内容:readfile( $file_name );
      

  3.   

    我在最前头放在:
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:filename=test.xls");
    header("Expires:0");
    header('Pragma: public' );
    header("Cache-control:must-revalidate,post-check=0,pre-check=0");就可以了.
    谢谢两位,现在结账