Discuz教程网

PHP批量下载图片文件代码

[复制链接]
authicon dly 发表于 2011-4-16 22:47:09 | 显示全部楼层 |阅读模式
  1. set_time_limit(0);//设置PHP超时时间 $imagesURLArray = array_unique($imagesURLArray ); foreach($imagesURLArray as $imagesURL) { echo $imagesURL; echo "<br/>"; file_put_contents(basename($imagesURL), file_get_contents($imagesURL)); }
复制代码

原理很简单,通过一个含有图片地址的数组循环,然后使用PHP的file_get_contents函数取得图片,在使用file_put_contents函数把图片保存下来。P.S:一定要加上设置PHP超时时间哦~!附上原文中通过php下载css中图片的代码:
  1. < ?php /* More & Original PHP Framwork Copyright (c) 2007 - 2008 IsMole Inc. Author: kimi Documentation: 下载样式文件中的图片,水水专用扒皮工具 */ //note 设置PHP超时时间 set_time_limit(0); //note 取得样式文件内容 $styleFileContent = file_get_contents('images/style.css'); //note 匹配出需要下载的URL地址 preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray); //note 循环需要下载的地址,逐个下载 $imagesURLArray = array_unique($imagesURLArray[1]); foreach($imagesURLArray as $imagesURL) { file_put_contents(basename($imagesURL), file_get_contents($imagesURL)); }
复制代码







上一篇:Discuz X1.5帖子推荐插件
下一篇:php正则匹配图片路径
authicon melody0721 发表于 2011-5-9 13:59:50 | 显示全部楼层
回贴下载呀
authicon 月之海洋 发表于 2011-5-11 18:59:52 | 显示全部楼层
顶你一下,好贴要顶!
authicon lilac_yao 发表于 2011-5-14 12:59:43 | 显示全部楼层
看一下啊,嘻嘻
authicon kurt226 发表于 2011-5-16 23:59:53 | 显示全部楼层
哦哦,发财了啊,看到好东西啦
authicon fhiejkl 发表于 2011-5-17 13:59:36 | 显示全部楼层
我回不回呢 考虑再三 还是不回了吧 ^_^
authicon lilac_yao 发表于 2011-5-17 18:59:54 | 显示全部楼层
好像不错的样子
authicon rin421 发表于 2011-5-19 07:59:37 | 显示全部楼层
看看  好像不错
authicon nmzc 发表于 2011-5-21 00:59:35 | 显示全部楼层
这个贴不错!!!
authicon mjz 发表于 2011-5-22 18:59:32 | 显示全部楼层
这个还是不错的!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-3 03:30

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表