Home >Backend Development >PHP Tutorial > fopen()打开当地文件,老打不开

fopen()打开当地文件,老打不开

WBOY
WBOYOriginal
2016-06-13 13:05:511867browse

fopen()打开本地文件,老打不开。
$dir="http://localhost/tmp_data/test.txt";
if(!($fp=fopen($dir,"r")))
{
  echo "打不开!";
  exit;
}
 while(!feof($fp))
  {
  $line = fgetss($fp);
  echo $line;
  echo "


";
  }
  fclose($fp);


?>  
代码如上,运行结果 


Warning: fopen(http://localhost/tmp_data/test.txt) [function.fopen]: failed to open stream: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 in C:\phpnow\htdocs\1.php on line 3

Fatal error: Maximum execution time of 30 seconds exceeded in C:\phpnow\htdocs\1.php on line 3

------解决方案--------------------
先在浏览器里查下http://localhost/tmp_data/test.txt这个能访问不?
------解决方案--------------------
allow_url_fopen 是不是开启状态
------解决方案--------------------
phpinfo(); //看一下
或者php.ini 查找
------解决方案--------------------
用file_get_contents试试
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn