2012-12-16 4 views
1

php://temp을 사용하여 tmp 파일을 만드는 코드가 있습니다.php : // temp 파일에 복사 하시겠습니까?

디버깅 목적 및 학습을 위해 정의 된 파일에 저장/복사하고 싶습니다. 그렇게 쉬운 방법이 있습니까? 큰 파일

//Somecode wrting to temp 
$tmp = fopen('php://temp', 'r+'); 
fwrite($tmp, 'test'); 
rewind($tmp); 


// Read and save to log.txt 
file_put_contents("log.txt",stream_get_contents($tmp)); 

큰 파일 구현 작업을 할 때

답변

2

당신은 stream_get_contents 또는 fwrite을 사용할 수 있습니다

set_time_limit(0); 

$file = "log.txt"; 
$final = fopen($file, "w+"); 

while (! feof($tmp)) { 
    fwrite($final, fgets($tmp)); 
} 

fclose($tmp); 
fclose($final); 
+0

'stream_copy_to_stream' 경우, – julp

+0

는 메모리 오류에서 발생할 수 있는가뿐만 아니라 흥미로운 일이 될 수 있습니다 tmp 파일은 매우 큽니다? 더 잘 작성해서는 안된다. – WonderLand

+0

당신이 읽고 쓰는 것에 달려 있습니다 .. 당신은 큰 내용물에서'fread'와'fwrite'를 한 줄씩 할 수 있습니다 ... – Baba

관련 문제