//第一:
$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");   

解决方案 »

  1.   

    第一个了可用fopen读进字中,直接echo $str 
      

  2.   

    int readfile ( string filename [, bool use_include_path [, resource context]])
    读入一个文件并写入到输出缓冲。 返回从文件中读入的字节数。如果出错返回 FALSE 并且除非是以 @readfile() 形式调用,否则会显示错误信息。没有看到从缓冲区调出显示的file_get_contents呢?
      

  3.   

    readfile($filename);去掉了就没有乱码了!但是下载还是不行!还有什么其他的好方法吗?
      

  4.   

    师哥们!我是要做文件下载!我现在有个Url如何下载那!
      

  5.   


    $filename   =  "http://".$_SERVER['SERVER_NAME'].$Url;header('Content-Disposition:   attachment;   filename=client.jpg');   
    header("Content-type: text/html");   
    file_get_contents($filename);
    这样是不报错的!但是文件下载下来是空的一张图片显示没有预览!是怎么回事!
      

  6.   

    我试了,把楼主代码第二行$Url改成$url就可以下载了,(注意大小写)<?php
    $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); 
    ?>
      

  7.   

    大小写的问题我已经改了!
    我的是Content-type: text/html
    不是Content-type:   application/octetstream
    我也改了!
    readfile()我也改成file_get_contents()文件可以下载了!但是下载后文件打开是空白!
      

  8.   

    除了这种方式PHP还有其他下载方式吗?
      

  9.   

    也许是我PHP环境设置有问题吧!
    readfile()我也改成file_get_contents() 后就不会有乱码出现了!现在就是下载后文件无法显示。PHP还有其他下载方式吗?
      

  10.   

    <?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);
    }
    ?>
      

  11.   

    14楼师哥请问 fread($file,50000); 
    这里的50000代表什么含义!我看是length,是什么长度。
      

  12.   

    header("Expires: 0");
    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);
      

  13.   

    14楼师哥请问 fread($file,50000); 
    这里的50000代表什么含义!我看是length,是什么长度。
    ---------------------
    这个50000指每次读取的字节数,直到读取到eof(文件末尾)
    你也可以写成4096