У меня есть большой файл, и мне нужно удалить последние 512 байт. Я не хочу дублировать файл.
Спасибо.
Вы должны использовать ftruncate(handle, file_size - 512) (получить размер файла с помощью функции filesize или fstat)
ftruncate(handle, file_size - 512)
filesize
fstat
Пример использования с fstat, ftruncate, fopen и fclose:
ftruncate
fopen
fclose
<?php $bytesToTruncate = 5; // how many bytes we are going to delete from the end of the file $handle = fopen('/home/francesco/mytest', 'r+'); // Open for reading and writing; place the file pointer at the beginning of the file. $stat = fstat($handle); $size = $stat['size'] - $bytesToTruncate; $size = $size < 0 ? 0 : $size; ftruncate($handle, $size); fclose($handle);
Я не тестировал его с большими файлами, но вы можете попробовать: