php fwrite w,PHP----fwrite(a+,w+)

/*

opendir() 打开目录 return: handle/false

readdir() 读取目录 return: handle/false

is_dir() 判断不否目录 return: handle/false

mkdir() 建立目录 return: true/false

getcwd() 得到当前目录 return: path/false

chdir() 改变当前目录 return: true/false

rmdir() 删除目录 return: true/false

rename() 为目录改名 return: true/false

scandir() 文件夹所有内容 return: array/false

模式描述

ronly read 只读。在文件的开头开始。

r+read/write 读/写。在文件的开头开始。

wonly write 只写。打开并清空文件的内容;如果文件不存在,则创建新文件。

w+read/write 读/写。打开并清空文件的内容;如果文件不存在,则创建新文件。

aand to 追加。打开并向文件文件的末端进行写操作,如果文件不存在,则创建新文件。

a+read/and to 读/追加。通过向文件末端写内容,来保持文件内容。

xonly write 只写。创建新文件。如果文件以存在,则返回 FALSE。

x+read/write 读/写。创建新文件。如果文件已存在,则返回 FALSE 和一个错误。

注释:如果 fopen() 无法打开指定文件,则返回 0 (false)。

*/

//a+

$file_path = $_SERVER['DOCUMENT_ROOT']."/wp_php/style/image/";

if(file_exists($file_path."write_a.txt")){

$handle = fopen($file_path."write_a.txt", "a+");

$content = "I is content1: a+\r\n";

if(fwrite($handle, $content)){

echo "
write file content(a+): success";

}else {

echo "
write file content(a+): fail";

}

}else{

echo "
write file content: not exist";

}

//w+

$handle = fopen($file_path."write_w.txt", "w+");

$content = "I is content2: w+\r\n";

if(fwrite($handle, $content)){

echo "
write file content(w+): success";

}else{

echo "
write file content(w+): fail";

}

//other:one param(file_put_contents)

/*

* FILE_APPEND 'a+' + file not exist create file

* LOCK_EX 'w+' + file not exist create file

*/

$content = "I is content3: file_put_contents \r\n";

if(file_put_contents($file_path."write-put.txt",$content, LOCK_EX)){

echo "
write file content(put w+): success";

}else{

echo "
write file content(put w+): fail";

}

fclose($handle);?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值