fopen函数是用来打开文件或者连接

若成功,则返回 true。若失败,则返回 false。

fopen打开连接是不能直接输出的 

使用:

<?php
$file = fopen("test.txt","r");
$file = fopen("/home/test/test.txt","r");
$file = fopen("/home/test/test.gif","wb");
$file = fopen("http://www.example.com/","r");
$file = fopen("ftp://user:password@example.com/test.txt","w");
?>

 

"r"    只读方式打开,将文件指针指向文件头。
"r+"    读写方式打开,将文件指针指向文件头。
"w"    写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。
"w+"    读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。

 

fopen打开连接,输出结果是  print_r();

public function dd(){
        $fh = fopen('http://www.baidu.com','r');
        print_r($fh);
    }

输出:

Resource id #42

 

fopen正确打开连接输出,要用到fgets

 public function dd(){
        $fh = fopen('http://www.baidu.com','r');
        while(!feof($fh)) {
            echo fgets($fh);
        }
    }

 

flock锁定和释放文件

若成功,则返回 true。若失败,则返回 false。

 

相关文章:

  • 2022-12-23
  • 2021-08-05
  • 2021-06-26
  • 2022-12-23
  • 2021-12-30
  • 2021-12-10
  • 2021-12-10
猜你喜欢
  • 2021-11-30
  • 2021-12-14
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案