Home > Backend Development > PHP Tutorial > 怎么把一个文件的内容复制到另外一个文件里

怎么把一个文件的内容复制到另外一个文件里

WBOY
Release: 2016-06-23 14:39:20
Original
3515 people have browsed it

比方说D盘 下面有个文件名a 文件夹  里面有个1.less文件和2.less文件  我想把1.less文件的内容复制到2.less里  
1.less内容
.eff
{
width:200px;
}

复制到2.less
还是
.eff
{
width:200px;
}
格式不能乱哦 不管2.less有没有内容都是覆盖哦


回复讨论(解决方案)

$source_file = "d:\\1.less";$target_file = "d:\\2.less";$t_fp = fopen($target_file, "w"); //以w打开,就是覆盖写。如果2.less不存在会创建文件。但是如果目录不存在的话,不会创建目录if(!$t_fp) return false;$content = readfile($source_file);if(!$content) return false;$flag = fwrite($t_fp, $content);if($flag === false) echo "不能写入文件";fclose($t_fp);
Copy after login

file_get_contents
file_put_contents

file_put_contents('a/2.less', file_get_contents('a/1.less'));

file_put_contents('b.txt',file_get_contents('a.txt'));

file_get_contents

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template