我有这段代码可以将行写入 new.txt(已经包含 2 行)文件,然后将此 txt 内容复制(备份)到新的 tmp.txt 文件中,但是 fread() 一直缺少 new.txt 文件中的新行复制到 tmp.txt tmp.txt 假设里面有 3 行,但是新添加的行丢失了。
$File ="new.txt";
$File2="tmp.txt";
//write into file
$handle = fopen ($File, 'a') or die("Cannot open File");
fwrite($handle,"some string");
fclose($handle );
//copy file
$handle2= fopen ($File, 'r') or die("Cannot open File");
$content = fread($handle2, filesize($File));
fclose($handle2);
$handle3 = fopen ($File2, 'w') or die("Cannot open File");
fwrite($handle3,$content);
fclose($handle3 );