日期:2014-05-17 浏览次数:20654 次
<?php $conn = mysql_connect("127.0.0.1","root","123456") or die("无法连接数据库"); @mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary",$conn); mysql_select_db("s517",$conn) or die("无法连接数据库"); global $db; function getImage($url, $filename="") { if(!$url) return false; if(!$filename) { $ext=strrchr(strtolower($url),".") ; if($ext!=".gif" && $ext!=".jpg" && $ext!=".png") return false; $str=explode('/',$url) ; $filename=$str[count($str)-1] ; } ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); $fp2=@fopen($filename, "a") ; fclose($fp2) ; return $filename; } //批量下载 $result = mysql_query("SELECT itemid, thumb FROM table LIMIT 0 , 300"); while($row = mysql_fetch_array($result)) { getImage($row["thumb"],""); echo $row["itemid"]."输出成功"; } ?>
$result = mysql_query("SELECT itemid, thumb FROM table LIMIT 0 , 1"); while($row = mysql_fetch_array($result)) { echo getImage($row["thumb"],"")."<br>"; echo $row["itemid"]."输出成功<br>"; }
------解决方案--------------------
直接file_get_content file_put_content