<?php header("Content_Type:text/html;charset=utf-8");
/*
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)。
*/
$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 file
if(rename($oldname, $newname)){
echo "rename file: success";
}else{
echo "rename file: fail";
}
//Copy file
if(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 file
if(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";
}
?>