我这里是PC端做服务器,现在别的电脑访问我这里,需要提示下载功能,怎么实现呢?好像是在index.php里写下载吧?完全没这方面的经验,不知道该怎么做。我加了这一段
<?php header("Content-type:application/rar");header("Content-Disposition:attachment;filename=.rar");readfile("E:\ziptest\2.1.1-b8.rar");?>
然后该怎么做呢?

解决方案 »

  1.   

    直接用html代码做个链接不行吗?
      

  2.   

    filename=aa.rar  //这里要取个名字。不然会形成rar 文件。
      

  3.   

    我还在我的XP上安了个XAMPP,做了个简单页面提供XXOO片下载给同学呢。
      

  4.   


    #down.php
    $file = 'ASDFGgg.pdf';
    _Download("files_dir/".$file, $file);function _Download($f_location,$f_name){
         header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
       header('Content-Description: File Transfer');
       header('Content-Type: application/octet-stream');
       header('Content-Length: ' . filesize($f_location));
       header('Content-Disposition: attachment; filename=' . basename($f_name));
       readfile($f_location); 
     }当运行down.php时,浏览器会自动打开下载提示框:
      

  5.   

    我在LocalSettings.php上加了这3行代码:header("Content-type:application/rar");header("Content-Disposition:attachment;filename=SQLite.rar");readfile("E:\ziptest\SQLite.rar");登录首页的时候,有下载提示,但是这个文件是300M的,我点下载之后查看到下载的时候200K,还有就是点下载之后返回首页该怎么做呢?现在是点下载页面就不见了
      

  6.   

    加上
    header('Content-Length: ' . filesize("E:\ziptest\SQLite.rar"));
    有什么效果?
      

  7.   


    <?php     
    $sourceFile = "E:/sqlite.db/sqlite.rar";     
         
    $outFile = "sqlite.rar";    
         
    $file_extension = strtolower(substr(strrchr($sourceFile, "."), 1));        
    if (!ereg("[tmp|txt|rar|pdf|doc]", $file_extension))exit (" download fail !");     
             
    if (!is_file($sourceFile)) {     
        die("<b>404 File not found!</b>");     
    }     
         
    $len = filesize($sourceFile);     
    $filename = basename($sourceFile);     
    $outFile_extension = strtolower(substr(strrchr($outFile, "."), 1));     
          
    switch ($outFile_extension) {     
        case "exe" :     
            $ctype = "application/octet-stream";     
            break;     
        case "zip" :     
            $ctype = "application/zip";     
            break;     
        case "mp3" :     
            $ctype = "audio/mpeg";     
            break;     
        case "mpg" :     
            $ctype = "video/mpeg";     
            break;     
        case "avi" :     
            $ctype = "video/x-msvideo";     
            break;     
        default :     
            $ctype = "application/force-download";     
    }     
        
    header("Cache-Control:");     
    header("Cache-Control: public");     
            
    header("Content-Type: $ctype");     
    header("Content-Disposition: attachment; filename=" . $outFile);     
    header("Accept-Ranges: bytes");     
         
    $size = filesize($sourceFile);     
           
    if (isset ($_SERVER['HTTP_RANGE'])) {        
           
        list ($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);     
      
        str_replace($range, "-", $range);    
        $size2 = $size -1;     
        $new_length = $size2 - $range;      
        header("HTTP/1.1 206 Partial Content");     
        header("Content-Length: $new_length");    
        header("Content-Range: bytes $range$size2/$size");    
    } else {     
        $size2 = $size -1;     
        header("Content-Range: bytes 0-$size2/$size");    
        header("Content-Length: " . $size);    
    }     
       
    $fp = fopen("$sourceFile", "rb");     
    fseek($fp, $range);     
    while (!feof($fp)) {     
       
        set_time_limit(0);     
        print (fread($fp, 1024 * 8));     
        flush();      
        ob_flush();     
    }     
    fclose($fp);     
    exit ();     
    ?>
    这个OK,对于超大文件也可以了。