php 将远程文件保存到本地

/**
 * 把远程文件保存到本地
 * @param string $remote_file_url
 * @param string $local_file
 */
function save_remote_file($remote_file_url, $local_file) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch,CURLOPT_URL, $remote_file_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $file_content = curl_exec($ch);
    curl_close($ch);
    $downloaded_file = fopen($local_file, 'w');
    fwrite($downloaded_file, $file_content);
    fclose($downloaded_file);
}

你可能感兴趣的:(php 将远程文件保存到本地)