2009-11-26 7 views

답변

4
$fp = fopen('logo.png', 'w'); 
fwrite($fp, file_get_contents('http://sstatic.net/so/img/logo.png')); 
fclose($fp); 
+0

그래서 $ FP =하면 fopen w '('./ 디렉토리/file.ext를 ' '); ??? 건배! –

3

I하고자했다 file_get_contents 평범하고 file_put_contents

$content = file_get_contents('http://sstatic.net/so/img/logo.png') 
file_put_contents('logo.png', $content); 

은 당신이 가지고있는 전체 파일을 일을 그런 식으로 메모리에 방류 될 것으로, 그래서 조심 것을 주목해야 할 것 memory_limit. 파일을 메모리에 넣지 않고 방법이 필요한 경우 curl 할 것입니다.

+0

컬을 사용하는 방법? – Mask

0

당신은 컬 요청 사용할 수 있습니다

public static function curlGet($url) 
{ 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $content = curl_exec($ch); 
    curl_close($ch); 
    return $content; 
} 

을하고 파일에 내용 응답을 쓰기

$fp = fopen('logo.png', 'w'); 
fwrite($fp, curlGet('http://sstatic.net/so/img/logo.png')); 
fclose($fp);