PHP----fwrite(a+,w+)
<?php /* 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 模式 描述 r only read 只读。在文件的开头开始。 r+ read/write 读/写。在文件的开头开始。 w only write 只写。打开并清空文件的内容;如果文件不存在,则创建新文件。 w+ read/write 读/写。打开并清空文件的内容;如果文件不存在,则创建新文件。 a and to 追加。打开并向文件文件的末端进行写操作,如果文件不存在,则创建新文件。 a+ read/and to 读/追加。通过向文件末端写内容,来保持文件内容。 x only 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+ "; if(fwrite($handle, $content)){ echo "<br> write file content(a+): success"; }else { echo "<br> write file content(a+): fail"; } }else{ echo "<br> write file content: not exist"; }
//w+ $handle = fopen($file_path."write_w.txt", "w+"); $content = "I is content2: w+ "; if(fwrite($handle, $content)){ echo "<br> write file content(w+): success"; }else{ echo "<br> 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 "; if(file_put_contents($file_path."write-put.txt",$content, LOCK_EX)){ echo "<br> write file content(put w+): success"; }else{ echo "<br> write file content(put w+): fail"; } <pre name="code" class="php">fclose($handle);?>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。