function get_file($url,$folder){
set_time_limit (24 * 60 * 60);
$destination_folder = $folder?$folder.'/':'';//文件下载保存目录
$newfname = $destination_folder . basename($url);
$file = fopen ($url, "rb");
if ($file) {
$newf = fopen ($newfname, "wb");
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
}
//php教程 方法二
// $url 是远程图片的完整url地址,不能为空。
// $filename 是可选变量: 如果为空,本地文件名将基于时间和日期
// 自动生成.
function grabimage($url,$filename="") {
if($url==""):return false;endif;
if($filename=="") {
$ext=strrchr($url,".");
if($ext!=".gif" && $ext!=".jpg"):return false;endif;
$filename=date("dmyhis").$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
$img=grabimage("yun_qi_img/000003.png","www.111cn.net.png");
if($img):echo '<pre><img src="'.$img.'"></pre>';
else:echo "false";
endif;
//fopen下载远程文件的函数:传入远程url和需要存储下载文件的文件夹名,结尾无需反斜线
//asp教程保存远程服务器图片
/*
sub saveremotefile(localfilename,remotefileurl)
dim ads,retrieval,getremotedata
set retrieval = server.createobject("microsoft.xmlhttp")
with retrieval
.open "get", remotefileurl, false, "", ""
.send
getremotedata = .responsebody
end with
set retrieval = nothing
set ads = server.createobject("adodb.stream")
with ads
.type = 1
.open
.write getremotedata
.savetofile localfilename,2
.cancel()
.close()
end with
set ads=nothing
end subremotefileurl = "" '获取远程图片
fileext = right(remotefileurl,4) '获取远程图片的格式'随机文件名称
randomize
rannum = int(9*10^3*rnd)+10^3
dtnow = now()
filename = year(dtnow) & right("0" & month(dtnow),2) & right("0" & day(dtnow),2) & right("0" & hour(dtnow),2) & right("0" & minute(dtnow),2) & right("0" & second(dtnow),2) & rannum & fileextlocalfilename = "./" '保存本地路径
if right(localfilename,1) <> "/" then localfilename = localfilename & "/"
savefile = server.mappath(localfilename & filename)
saveremotefile savefile,remotefileurl '保存远程图片
response.write "保存成功,<a href=""" & localfilename & filename & """ target=""_blank"">点击查看图片文件....</a>"
*/
//方法三
/*保存图片函数*/
function saveimage($url) //保存url中的图片文件到本地的imges文件夹下,名称不变,返回图片的路径和名称
{
if($url==""):return false;endif;
/*保存路径*/
$path="movieimg/".date('y-m-d'); //保存路径
if(!file_exists($path))
{
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir("$path", 0700);
}
$name=strrchr($url,"/");
$filename=$path.$name;
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
?>