php的fopen问题

sssxueren 2002-04-08 05:40:54
我用php写的一个简单的东西,

$UsernumFile = "/home/zsns7sdxau3e6r6ecn/wwwroot/tmp/usersnum.txt";

if (!file_exists($UsernumFile)) {
echo "文件不存在\n";

$fp = fopen($UsernumFile,"w");
if($fp==false)
echo "创建文件出错\n";

$num = fputs($fp,"0");
echo $num."\n";

fclose($fp);
}
else
echo "找到文件\n";

$fp = fopen($UsernumFile,"rw"); ******
if($fp==false)
echo "打开文件出错!";

$num = fgets($fp,5);
$num++;

echo $num;
fclose($fp);

可以创建文件,再次运行,并且可以找到文件,但,就是在fopen(,"rw");的时候不能打开文件,为什么?

而且,好像php要求写入的目录的属性是777吧,我在那个目录里面,用ftp不能看到文件
...全文
41 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
platinum 2002-04-08
  • 打赏
  • 举报
回复
有 rw 这么一说吗?又是只读又是可写……?

mode may be any of the following:

'r' - Open for reading only; place the file pointer at the beginning of the file.

'r+' - Open for reading and writing; place the file pointer at the beginning of the file.

'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.


Note: The mode may contain the letter 'b'. This is useful only on systems which differentiate between binary and text files (i.e. Windows. It's useless on Unix). If not needed, this will be ignored.
hqywork 2002-04-08
  • 打赏
  • 举报
回复
你可以定义写出文件的属性,你看一个PHP手册吧,FOPEN可以的。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧