PHP之打开文件

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

 

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

报警告: Warning: fopen(F:Books投行笔记.txt): failed to open stream: No error in D:Apache24x64htdocsTest.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:Apache24x64htdocsTest.php on line 383

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

 

尝试把r改为R:

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

 

报警告: Warning: fopen(F:Books1.txt): failed to open stream: No error in D:Apache24x64htdocsTest.php on line 383

还是失败。

 

总结:

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

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

 

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

原文地址:https://www.cnblogs.com/Sabre/p/5736607.html