2011-11-16 104 views
0

我正在尝试使用单独国家的文本文件逐行列出下拉列表。FilePointer拒绝打开

问题是,无论什么原因,我的文件拒绝打开。

下面的代码:

<?php 
$path = realpath(dirname(__FILE__)); 
require_once('upload.controller.php'); 
$filePath = $path.'/../includes/_notes/countries.txt'; 
$handle = fopen($filePath, "r"); 


?> 
<!DOCTYPE html> 
<html> 
    <head> 
     <link rel="stylesheet" type="text/css" href="../includes/css/adsmanager.css" /> 
     <script type="text/javascript" src="../includes/js/.."></script> 
    </head> 
    <body> 
     <!--<form method="post" action="upload.controller.php">--> 
      <!--<select> 
       <script type="text/javascript" src="includes/js/countries.js" /></script> --> 
       <?php 

        if ($handle) { 

         while(($buffer = fgets($file)) != false) { 
          var_dump($buffer); 
         } 

         if (!feof($handle)) { 
          die("failed to open file"); 
         } 
        } 
        fclose($handle); 
       ?> 
      <!--</select> 
     </form>--> 
    </body> 
</html> 

与我一起输出:

string(66) "/var/www/patention/modules/upload/../includes/_notes/countries.txt" failed to open file 

难道我做错了什么?我从 PHP Manual上直接列出的例子中拿出来。随着this

回答

1

你的文件的路径似乎是错误的我:

"/var/www/patention/modules/upload/../includes/_notes/countries.txt" 

..用于相对目录。

如果countries.txt位于内includes/_notes/includes是在您的.PHP脚本的父目录,改为只

../includes/_notes/countries.txt 

总之,不追加$path$filePath

路径

编辑:

在这一行:

while(($buffer = fgets($file)) != false) 

变化

while(($buffer = fgets($handle)) != false) 
+0

是的,我试过,之前可惜没有奏效。这就是为什么我尝试了realpath(dirname(__ FILE__))路径,并将其添加到文件路径。任何其他想法? – zeboidlund

+0

你有什么错误? – xbonez

+0

我没有得到任何错误,这是奇怪的事情。如果feof($ handle)返回false,我只需要一个die语句。 – zeboidlund