I have a large file and you need to delete the last 512 bytes. I do not want to duplicate the file.
Thank.
You should use ftruncate(handle, file_size - 512)(get file size using function filesizeor fstat)
ftruncate(handle, file_size - 512)
filesize
fstat
I have not tested it with large files, but you can try:
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);
Source: https://habr.com/ru/post/1782688/More articles:почему '[self.pickerSubArray indexOfObject: self.txtSubCategory.text]' return '2147483647'? - objective-cWhat to store in a session - phpC # Winforms: accessing Outlook with multiple mailboxes - c #How to find out if a domain is registered with a client? - javascriptGoogle Analytics API for Commercial Website - apiAdd .html when rewriting url in htaccess? - urlHow to use NGen.NET app correctly during installation - installerResolving name conflicts in C ++ - c ++Create a scaled circle of cards - mathJavascript / html: How to create a random number between number A and number B? - javascriptAll Articles