こんにちは。 r+モードは試してみましたか?
<?php
$fileo = "overwrite.dat"; $filei = "insert.dat"; $length = 10; $strings = "abcdefghijklmnopqrstuvwxyz"; $add_strings = "012";
file_put_contents($fileo, $strings);
$fp = fopen($fileo, "r+"); if(fseek($fp, -$length, SEEK_END) == 0) { fwrite($fp, $add_strings); } fclose($fp);
print "overwrite: " . $strings . " -> " . file_get_contents($fileo) . "\n";
file_put_contents($filei, $strings);
$fp = fopen($filei, "r+"); if(fseek($fp, -$length, SEEK_END) == 0) { $data = fread($fp, $length); if(fseek($fp, -$length, SEEK_END) == 0) { fwrite($fp, $add_strings . $data); } } fclose($fp);
print " insert: " . $strings . " -> " . file_get_contents($filei) . "\n";
?>
|