php写入、删除与复制文件的方法

yipeiwu_com7年前PHP代码库

本文实例讲述了php写入、删除与复制文件的方法。分享给大家供大家参考。具体如下:

1. 写入:

<?php 
$filename = "Test//file.txt"; 
$file = fopen($filename, "w"); //以写模式打开文件 
fwrite($file, "Hello, world!/n"); //写入第一行 
fwrite($file, "This is a test!/n"); //写入第二行 
fclose($file); //关闭文件 
?> 

2. 删除:

<?php 
$filename = "Test//file.txt"; 
unlink($filename); //删除文件 
?> 

3.复制:

<?php 
$filename1 = "Test//file.txt"; 
$filename2 = "Test//file.bak"; 
copy($filename1, $filename2); //复制文件 
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

php UTF8 文件的签名问题

也就是 有BOM 格式编码,或者 无BOM格式编码。 如果看文件的内容,是看不出任何差别的,以下列文件(schema.sqlite.sql)内容为例: schema.sqlite.sql...

PHP无刷新上传文件实现代码

index.html 复制代码 代码如下: <html> <head> <title>无刷新上传文件</title> <meta C...

php array_map使用自定义的函数处理数组中的每个值

array_map 将回调函数作用到给定数组的单元上。 说明 array array_map ( callable $callback , array $arr1 [, array $....

php 遍历数据表数据并列表横向排列的代码

复制代码 代码如下:<?php $a = array (1,2,3,4,5,6,7,8,9,10,11); $i = 0; ?> <table border=1>...

PHP fopen函数用法实例讲解

php fopen()函数用于打开文件或者 URL。 php fopen()函数 语法 作用:打开文件或者 URL。 语法: fopen(filename,mode,include_...