2012-03-31 95 views
0

當我在php中創建一個增長的文件時,我通常使用帶有FILE_APPEND和LOCK_EX標誌的_file_put_contents_函數。 不,我有一個與mplayer一起玩的視頻文件。 爲了避免文件變得太大,我想覆蓋已經播放的數據而不截斷文件。在bash中,有一個簡單的函數來做到這一點:覆蓋數據而不截斷文件

dd if=/dev/zero of=myoutputfile conv=notrunc count=1 bs=128k 

這裏解釋http://en.wikipedia.org/wiki//dev/zero

有沒有一種方法,以獲得在PHP是一回事嗎?

+1

http://nz.php.net/manual/en/function.ftruncate.php爲什麼你這麼懶? – zerkms 2012-03-31 10:48:39

回答

0

如何:

$h = fopen("myoutput", "r+"); // '+' means also for writing without truncating 
fseek($h, $wherever_you_need); 
fwrite($h, $data); // overwrite 
fclose($h); 
+0

謝謝你的作品! :) – Matteo 2012-03-31 14:28:22