PHP之打开文件

时间:2023-03-09 08:42:34
PHP之打开文件

PHP之打开文件

今天在看《PHP与MySQL程序设计(第四版)》(ISBN: 9787115253521)的时候,183页,如下图:

PHP之打开文件

尝试:$file = fopen("F:\Books\投行笔记.txt","R");

报警告: Warning: fopen(F:\Books\投行笔记.txt): failed to open stream: No error in D:\Apache24x64\htdocs\Test.php on line 383

实际上就是打开失败。

尝试:$file = fopen("F:\Books\投行笔记.txt","r");

报警告:Warning: fopen(F:\Books\投行笔记.txt): failed to open stream: No such file or directory in D:\Apache24x64\htdocs\Test.php on line 383

看来是参数正确,但文件名有问题。把文件名改为1.txt,可以打开。

尝试把r改为R:

尝试:$file = fopen("F:\Books\1.txt","R");

报警告: Warning: fopen(F:\Books\1.txt): failed to open stream: No error in D:\Apache24x64\htdocs\Test.php on line 383

还是失败。

总结:

一、fopen不支持中文名,按说这是不应该的,一定是哪里设置得有问题或者某个选项没开,待查。

二、fopen的第二个参数应当是小写。我这里的PHP版本是php7.0.8,不知道5.3是不是这样的。

PHP之打开文件

经查,书上的有问题,应当是小写