//curl-get
function curl_get($url, $timeout = 10)
{
$ch = curl_init();//初始化
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //禁止服务器端的验证
//伪装请求来源,绕过防盗
curl_setopt($ch,CURLOPT_REFERER,"http://www.ding.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//服务器5秒内没有响应,脚本就会断开连接
$file_contents = curl_exec($ch);//运行curl
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $file_contents;
}
//http://oss.houdunren.com/lesson_video/水印类/1,水印类简介.mp4
$url = '要下载文件的地址';
$filename = '要保存的下载文件名称';
header("Content-Disposition:attachment;filename=".$filename);
echo curl_get($url);
function curl_post($url, array $params = array(), $timeout = 5)
{
$ch = curl_init();//初始化
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return ($data);
}