PHP抓取远程图片到本地
时间:2011-04-14 来源:wk0423
<?php
function GetImage($url, $filename = "") {
if ($url == "") {
return false;
}
if ($filename == "") {
$ext = strrchr ( $url, "." );
if ($ext != ".gif" && $ext != ".jpg") {
return false;
}
$filename = time () . $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;
}
GetImage ( "http://XXXXX" );
相关阅读 更多 +