PHP:fopen:没有这样的文件或目录 [英] PHP: fopen: No such file or directory
问题描述
我正在尝试为我的网站创建一个日志文件.为此,我使用以下代码尝试打开文件.现在该文件尚不存在,但是文档指出,添加"a +"标志可确保在不存在的情况下创建该文件.
I am trying to create write a log file for my web site. To do this I use the following code to try and open the file. Now the file does not exist yet, but the documentation states that adding "a+" flag ensures that the file is created if it does not exist.
$file = fopen($_SERVER['DOCUMENT_ROOT']."/logs/mylogfile.txt", "a+");
上面的代码给我以下错误...
The above code gives me the following error...
Warning: fopen(E:/wamp/www/logs/mylogfile.txt) [function.fopen]: failed to open stream: No such file or directory
我在做什么错?如果这是一个愚蠢的问题,请原谅,我对PHP还是很陌生.
What am I doing wrong ? Please excuse me if this is stupid question, I am very new to PHP.
推荐答案
fopen的第二个参数"a +"如果目录存在,则只能创建文件.确保日志目录在那里.如果不是这种情况,请使用:
fopen's 2nd parameter "a+" can only create the file if the directory exists. Make sure the logs directory is there. If it's not the case use:
mkdir($_SERVER['DOCUMENT_ROOT']."/logs/", 0755, true);
(真是键)在fopen()之前
(true is the key) before fopen()
这篇关于PHP:fopen:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!