2013-03-18 2 views

답변

10

특정 길이의 바이트 청크를 읽을 수있는 기능 (이 상기 파일의 특정 오프셋에서) 문자열 변수로 그러나

$buffer = stream_get_contents($handle, $length = 512, $offset = 0); 

, 기록 할 stream_put_contents() 함수 없다 지정된 위치/오프셋 (offset)의 스트림에 스트링 버퍼 관련 함수는 file_put_contents()이지만 특정 오프셋에서 파일 핸들 리소스에 쓸 수 없습니다. $buffer의 길이가이 제대로 작동하지 않습니다 해결되지 않으면

$handle = fopen($filename, 'c+'); 
$buffer = stream_get_contents($handle, $length = 512, $offset = 0); 

// ... change $buffer ... 

$bytes_written = false; 
if (0 === fseek($handle, $offset)) { 
    $bytes_written = fwrite($handle, $buffer, $length); 
} 
fclose($handle); 

: 여기

$bytes_written = false; 
if (0 === fseek($handle, $offset)) { 
    $bytes_written = fwrite($handle, $buffer, $length); 
} 

전체 사진입니다 : 그러나 fseek()fwrite()가 있다고 할있다. 이 경우 두 개의 파일로 작업하고 How to update csv column names with database table header에 설명 또는 파일이 크지 않은 경우가해야 할 수도 있습니다으로 stream_copy_to_stream()을 사용하는 것이 좋습니다 그 메모리 :

$buffer = file_get_contents($filename); 

// ... change $buffer ... 

file_put_contents($filename, $buffer); 
관련 문제