$url="/admin/upload/client.jpg";
$urlRs = explode("/", $url);
$filename=$url[count($urlRs)-1];$fileurl="http://".$_SERVER['SERVER_NAME'].$url;header('Content-Disposition:attachment;filename='.$filename);   
header("Content-type: text/html");   
echo file_get_contents("http://www.aaa.com".$fileurl);//or echo file_get_contents($_SERVER[“DOCUMENT_ROOT”].$fileurl);
注意file_get_contents:要么给http:全路径,要么用绝对路径,尽量不要用相对路径

解决方案 »

  1.   


    可以先echo一下传入file_get_contents的路径看对不对
      

  2.   

    $fileurl="http://".$_SERVER['SERVER_NAME'].$url;
    这个和"http://www.aaa.com".$fileurl是不是重了啊
      

  3.   

    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=$filename");
    header("Content-Transfer-Encoding: binary");
    readfile($fileurl);
      

  4.   

    $fileurl="http://".$_SERVER['SERVER_NAME'].$url;
    echo $fileurl;
    看看。
      

  5.   

    header("Content-Type: application/download");
    header("Content-Disposition: attachment;filename=$filename");
    readfile($fileurl);
      

  6.   

    $url="/admin/upload/client.jpg";
    $urlRs = explode("/", $url);
    $filename=$url[count($urlRs)-1];$fileurl="http://".$_SERVER['SERVER_NAME'].$url;
    echo $fileurl;header( "Content-Type:   application/force-download "); 
    header( "Content-Disposition:   attachment;   filename= ".basename($filename)); 
    $data = file_get_contents($fileurl);
    echo $data;
      

  7.   

     file_get_contents出来了,你要echo或者print他的阿print file_get_contents($something);
      

  8.   

    下载档案用 readfile , 怎么都跑到 file_get_contents 了 =.=
      

  9.   

    不要用 echo file_get_contents(...) 它很费内存
    直接用 readfile(...)
      

  10.   

    file_get_contents返回的是字符串(即文件内容)但不显示出来,所以,楼主要将文件内容输出,就要用
    echo file_get_contents($fileurl);
    但是推荐用readfile进行读取(下载),不用file_get_contents储存到内存再下载,readfile直接输出,代码:
    readfile($fileurl);