2010-07-08 5 views

답변

1

외부 서버에서 다운로드하여 파일 시스템에 쓸 수 있습니다 (현재 디렉토리에 대한 권한이있는 경우). 그렇지 않으면/tmp 또는 권한이있는 모든 곳에 쓸 수 있습니다.

$file = 'test.jpg'; 
file_put_contents($file, 
    file_get_contents("http://example.com/" . $file) 
); 
0

file_get_contents를 사용할 수 있습니다. php는 네트워크 스트림을 지원합니다. 폴더는 외부에서 액세스 할 수 있어야합니다.

1

또한 allow_url_fopen을 설정 PHP를 사용할 수없는 경우 유용 할 수있는, 이것에 대한 컬을 사용할 수 있습니다

<?php 

function fetch_url($url, $output_file) { 
    $stream = fopen($output_file, 'w'); 
    if ($stream === false) { 
     throw new Exception('Cannot write to file'); 
    } 

    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_FILE, $stream); 
    $result = curl_exec($curl); 

    curl_close($curl); 
    fclose($stream); 

    if ($result === false) { 
     throw new Exception('cURL Error: ' . curl_error($curl)); 
    } 
} 

fetch_url('http://www.example.com', '/some/file'); 
관련 문제