php函数抓取远程图片到本地
时间:2021-07-01 10:21:17
帮助过:19人阅读
//php ob函数库抓取远程图片 - 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" );
|