Hai*_*vgi 32
你想要这样的东西吗?
function get_file($file, $local_path, $newfilename)
{
$err_msg = '';
echo "<br>Attempting message download for $file<br>";
$out = fopen($local_path.$newfilename,"wb");
if ($out == FALSE){
print "File not opened<br>";
exit;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $file);
curl_exec($ch);
echo "<br>Error is : ".curl_error ( $ch);
curl_close($ch);
//fclose($handle);
}//end function
Run Code Online (Sandbox Code Playgroud)
功能:它的功能和接受三个参数
get_file($file, $local_path, $newfilename)
Run Code Online (Sandbox Code Playgroud)
$file :是要检索的对象的文件名
$local_path :是存储对象的目录的本地路径
$newfilename :是本地系统上的新文件名
您可以使用:
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$out = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
$fp = fopen('data.txt', 'w');
fwrite($fp, $out);
fclose($fp);
?>
Run Code Online (Sandbox Code Playgroud)
请参阅:http://jp2.php.net/manual/en/function.curl-exec.php 和http://us3.php.net/manual/en/function.fwrite.php