使用WAMP:在Windows上读取文件权限


Using WAMP: Read file permissions on Windows

我的系统:windos xp

我已将文件的所有权限授予所有用户。

但我不能读取文件,但我得到了文件大小,

为什么会发生这种事,原因我无法确定。

我该怎么办才能解决这个问题。

代码

$fileName = "1.php";
if (floatval(phpversion()) >= 4.3) {
  //loading data
  $fileData = file_get_contents($fileName);
  print(filesize($fileName));
} else {
  //if file not exist then return -3
  if (!file_exists($fileName)) {
    eturn -3;
  }
  $fp = fopen($fileName, 'r');
  // if file is not open in read mode then return -2
  if (!$fp) return -2;
  $fileData = '';
  print(filesize($fileName));
  //checking end of file
  while(!feof($fp))
    $fileData .= fgetc($fileName);
  fclose($fp);
}
echo $fileData;

您的问题是:

  • eturn应该说return——这可能是一个解析错误
  • 实际的问题是,您调用fgetc($fileName)时应该是fgetc($fp)。您将文件名的字符串传递给fgetc(),而不是您创建的文件指针

更改:

$fileData .= fgetc($fileName);

$filedata .= fgetc($fp);