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

<?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";
}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值