Override data without truncating the file
-
28-05-2021 - |
Question
When I make a growing file in php, I usually use the _file_put_contents_ function with FILE_APPEND and LOCK_EX flags. Non, I have a growing video file that I play with mplayer. To avoid that the file becomes too big, I want to overwrite data that I've already played without truncating the file. In bash, there is a simple function to do this:
dd if=/dev/zero of=myoutputfile conv=notrunc count=1 bs=128k
explained here http://en.wikipedia.org/wiki//dev/zero
Is there a way to obtain the same thing in php?
La solution
How about this:
$h = fopen("myoutput", "r+"); // '+' means also for writing without truncating
fseek($h, $wherever_you_need);
fwrite($h, $data); // overwrite
fclose($h);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow