PHP----fcreate(create,delete,copy)

来源:互联网 发布:帝国cms淘宝客模板 编辑:程序博客网 时间:2024/06/07 08:01
<?php header("Content_Type:text/html;charset=utf-8");/*opendir()    打开目录            return: handle/falsereaddir()    读取目录            return: handle/falseis_dir()     判断不否目录    return: handle/falsemkdir()      建立目录            return: true/falsegetcwd()     得到当前目录    return: path/falsechdir()      改变当前目录    return: true/falsermdir()      删除目录            return: true/falserename()  为目录改名         return: true/falsescandir()    文件夹所有内容  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)。*/
$file_path = $_SERVER['DOCUMENT_ROOT']."/wp_php/style/image/";//create null file(file not exist create ,exist no create file)if(touch($file_path."touch1.txt")){echo "<br> create null file:success";}else{echo "<br> create null file:fail";}
//create file(同时往file 里加内容)if(!file_exists($file_path."create1.txt")){$handle = fopen($file_path."create1.txt", "w+");if(fwrite($handle, "create file content")){echo "<br> create file: success";}else{echo "<br> create file: fail";}fclose($handle);}else{echo "<br> create file: exist";}//rename fileif(rename($oldname, $newname)){echo "rename file: success";}else{echo "rename file: fail";}
//Copy fileif(file_exists($file_path."create1.txt")){if(copy($file_path."create1.txt", $file_path."create2.txt")){echo "<br> copy file: success";}else{echo "<br> copy file:fail";}}else{echo "<br> copy file: not exist";}
//chinaese char  中文字符路径乱码处理$file_path = iconv("utf-8", "gb2312", "D:\\新建文件夹\\2.jpg");if(!is_file("D:\\22.jpg")){if(copy($file_path, "D:\\22.jpg")){echo "<br />"."coyp file success";}else{echo "<br />"."coyp file fail";}}else{echo "<br />"."coyp file: exist";}
//Delete fileif(file_exists($file_path."create2.txt")){if(unlink($file_path."create2.txt")){echo "<br> delete file success";}else{echo "<br> delete file fail";}}else{echo "<br> delete file: not exist";}?>

0 0
原创粉丝点击