足球游戏_中国足彩网¥体育资讯$

PHP抓取远程图片并另存为的实现方法
来源:易贤网 阅读:1982 次 日期:2014-08-21 17:14:21
温馨提示:易贤网小编为您整理了“PHP抓取远程图片并另存为的实现方法”,方便广大网友查阅!

下面是源代码,及其相关解释

//URL是远程的完整图片地址,不能为空, $filename 是另存为的图片名字

//默认把图片放在以此脚本相同的目录里

function GrabImage($url, $filename=""){

//$url 为空则返回 false;

if($url == ""){return false;}

$ext = strrchr($url, ".");//得到图片的扩展名

if($ext != ".gif" && $ext != ".jpg" && $ext != ".bmp"){echo "格式不支持!";return false;}

if($filename == ""){$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;

}

//测试

GrabImage("http://www.66xing.com/UploadFile/200609082320515027.bmp", "as.gif");

?>

相关描述:

ob_start : 打开输出缓冲

This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. (输出是在内部缓冲储存)

//

readfile : 读入一个文件并写入到输出缓冲

返回从文件中读入的字节数。如果出错返回 FALSE 并且除非是以 @readfile() 形式调用,否则会显示错误信息。

//

ob_get_contents : Return the contents of the output buffer(返回输出缓冲的内容)

This will return the contents of the output buffer without clearing it or FALSE, if output buffering isn't active. (如果输出缓冲没有活动(打开),则返回 FALSE)

//

ob_end_clean() : Clean (erase) the output buffer and turn off output buffering(清除输出缓冲)

This function discards(丢弃) the contents of the topmost output buffer and turns off this output buffering.(丢弃并且关掉) If you want to further process the buffer's contents you have to call ob_get_contents() before ob_end_clean() as the buffer contents are discarded when ob_end_clean() is called. (如果要用缓冲内容,则在清理输出缓冲之前要先调用 ob_get_contents())The function returns TRUE when it successfully discarded one buffer and FALSE otherwise. Reasons for failure are first that you called the function without an active buffer or that for some reason a buffer could not be deleted (possible for special buffer).

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看网络编程
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标