2010-12-29 3 views

답변

10

당신은 filesize과 파일 크기를 얻을 ftruncate(handle, file_size - 512)을 (사용해야 또는 fstat 기능)

+0

감사합니다. 그게 내가 원했던 것. – SaltLake

+2

큰 파일에서 어떻게 작동 했습니까? 처리해 봤어? – profitphp

+0

@profitphp Havenot은 실제 대용량 파일로 테스트했지만 200-300 Mb의 파일은 정상적으로 작동합니다. – SaltLake

2

사용 예는 fstat, ftruncate, fopenfclose :

<?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); 
관련 문제