做了一个php下载页面,用到readfile(filepath)or die("File not found.");总是提示文件找不到。
下载文件相对于down.php在 ./admin/Upload 下,而我在down.php中用到的路径 filepath 是./admin/Upload/xxx.xxx
请问文件路径存在问题吗?应当怎样呢?

解决方案 »

  1.   

    down.php文件:
    <?php
      $file_path=$_GET["path"];
      $file_name=$_GET["name"];   
      //$fp=fopen($file_path,"r");    
      header("Content-Type: application/force-download"); 
      header("Content-Transfer-Encoding: binary"); 
      header("Content-Length: ".filesize($file_path));   
      header("Content-Disposition: attachment; filename=".$file_name);   
      readfile($file_path) or die("File not found.");
      //echo   fread($fp,filesize($file_path));   
      //fclose($fp); 
    ?>
    文件结构:
    down.php
    ./admin/Upload/xxx.xxx
    为什么文件明明存在却下载不下来,下载下来的文件里只有提示File not found.
      

  2.   

    <?php 
      $file_path=$_GET["path"]; 
      $file_name=$_GET["name"];
      $file_name=$file_path.$file_name;   
      header("Content-Type: application/force-download"); 
      header("Content-Transfer-Encoding: binary"); 
      header("Content-Length: ".filesize($file_name));  
      header("Content-Disposition: attachment; filename=".$file_name);  
      readfile($file_name) or die("File not found."); 
    ?>
      

  3.   


    file_path=$_GET["path"];
      $file_name=$_GET["name"]; 
      $fp=fopen($file_path,"r");   
      header("Content-Type: application/force-download");
      header("Content-Transfer-Encoding: binary");
      header("Content-Length: ".filesize($file_path)); 
      header("Content-Disposition: attachment; filename=".$file_name); 
     //readfile($file_path) or die("File not found.");
      echo fread($fp,filesize($file_path)); 
      fclose($fp); 用fopen()呢?
      

  4.   

    我的$file_path即是./admin/Upload/xxx.xxx (路径加文件名)。
    用fopen()一样的啊。也是提示找不到文件。
      

  5.   

    $file_name=$file_path."/".$file_name;  看看这样行不
      

  6.   

    传给down.php的参数是这样的down.php?path=./admin/Upload/xxx.xxx & name=xxx.xxx
    本地测试好像没问题,传到服务器上总是file not found.
      

  7.   

    linux ? 注意文件名的大小写