解决方案 »

  1.   

    不在 web 服务器管理范围的文件,就不能用 http 协议访问
    你需要通过 php 程序中转
      

  2.   

    哪到底该如何做呢? 我的filelist页码是可以指到任何文件夹的。是否可以修改成嵌入文件打开呢? 页码如下:<?phperror_reporting(0);
    $basedir = "c:/filelist";
    if(!is_dir($basedir)) $basedir = dirname(__FILE__);
    $file_name = $_GET['downfile'];
    if(!empty($file_name)){$file_dir = $basedir . "/" . $file_name;if(dirname(realpath($file_dir)) < $basedir){echo "Permission Denied!";exit;}if (!file_exists($file_dir)) {echo "File Not Found!";exit;} else {$file = fopen($file_dir,"r");Header("Content-type: application/octet-stream");Header("Accept-Ranges: bytes");Header("Accept-Length: ".filesize($file_dir));Header("Content-Disposition: attachment; filename=" . $file_name);echo fread($file,filesize($file_dir));fclose($file);exit;}
    }
    header("Content-type: text/html; charset=utf-8");
    $requestDir = $_GET['dir'];
    if(empty($requestDir)){$dir = $basedir;
    }else{$dir = $basedir . "/" . $requestDir;
    }
    $dir = realpath($dir);
    if($dir < $basedir) $dir = $basedir;
    ?><html>
    <head>
    <title>File Listing</title>
    <STYLE type="text/css">
    body {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;
    }td {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;
    }input {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;
    }.title {font-family: "Verdana", "Tahoma";font-size: 22px;font-weight: bold;
    }
    </STYLE>
    </head>
    <body><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td class="title">File Listing</td><td align="right" valign="bottom"><font color="#FF0000"><h2><a href="logout.php">Sign Out</a></h2></font></td></tr></table><hr width="100%" style="border:1px dashed black; height:1px"><table width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td><?php $predir = realpath($dir . "/../");if($predir > $basedir) $predir = str_replace($basedir . "/","",$predir);if($predir == $basedir) $predir = ".";if($dir > $basedir) echo "<a href=\"?dir=". $predir ."\">Up Level</a>";?></td></tr><?php$dirs=@opendir($dir);$count = 0;while($file=@readdir($dirs)) {$b="$dir/$file";$a=@is_dir($b);if($a=="1"){if($file!=".."&&$file!=".") {if($count < 1){$count ++;echo "<tr>\n";echo "<td><b>Folder</b></td>\n";echo "</tr>\n";}echo "<tr>\n";echo "<td><a href=\"?dir=" . ($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '') . urlencode($file)."\">$file</a></td>\n";echo "</tr>\n";}}}@closedir($dirs);?></table><hr width="100%" style="border:1px dashed black; height:1px"><table width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td><b>Filename</b></td><td><b>Date</b></td><td><b>Size</b></td><td><b>Action</b></td></tr><?php$dirs=@opendir($dir);while ($file=@readdir($dirs)) {$b="$dir/$file";$a=@is_dir($b);if($a=="0"){$size=@filesize("$dir/$file");$size=$size/1024 ;$size= @number_format($size,2);$lastsave=@date("Y-n-d H:i:s",filemtime("$dir/$file"));echo "<tr>\n";echo "<td>$file</td>\n";echo "<td>$lastsave</td>\n";echo "<td>$size KB</td>\n";echo "<td><a href=\"?downfile=".($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '').urlencode($file)."\">Download</a></td>\n";echo "</tr>\n";}}@closedir($dirs);?></table>
    <hr width="100%" style="border:1px dashed black; height:1px">
    <?php include View::getView('side'); include View::getView('footer');?>
      

  3.   

    已解决,用以下的代码即可。<?php $file_handle = fopen("outsidefile/file.txt", "r");while (!feof($file_handle)) {$line_of_text = fgets($file_handle);
    print $line_of_text . "<BR>";}fclose($file_handle);
    ?>