Bing搜索每天的背景图片都很精致,为了方便收集特意搭了一个奋斗博客相册保存,如果每天手工下载上传恐怕很难保证一张不漏。
在网上找到一个PHP获取Bing每日背景图片的方法,只需要在服务器上添加Crontab任务就会每天自动下载,不需要人工干预相当方便。
将以下代码保存为bingimage.php上传到服务器上并设置权限775。其中#!/usr/bin/php 是服务器php路径,$savePath = ”; 是图片保存位置。
#!/usr/bin/php <?php $savePath = '/home/wwwroot/www.xxx.com/photo/photos/'; if (!function_exists('file_get_contents')) { exit('Can\'t support file_get_contents() !'); } $url = 'http://cn.bing.com/'; $bing = file_get_contents($url); /** url:'/fd/hpk2/OaklandBayBridge_ZH-CN614487829.jpg' */ $pattern = '/url:\'(.*)\'/U'; $matches = array(); preg_match($pattern, $bing, $matches); $arrPathInfo = pathinfo($matches[1]); $imageName = $arrPathInfo['basename']; $image = file_get_contents($url.$matches[1]); $imagePath = $savePath !== '' ? $savePath.$imageName : $imageName; file_put_contents($imagePath, $image); ?>
登陆到服务器上运行 crontab -e 添加任务:00 00 * * * /home/www/photo/bingimage.php 晚上凌晨自动下载Bing每日背景图片。
“PHP获取Bing每日背景图片”上的8条回复
确实很精致啊~ 收藏下。
博主过来支持啦
看不懂代码是我的一大遗憾呀
看着代码就头晕!
微软还是蛮有才的
过来支持你 了……
看代码看的都晕了,上班看,下班逛逛博客有看到了
我也不懂代码!
bing的图片很精致???