Home >Backend Development >PHP Tutorial >批量下载的图片都是0字节,该怎么解决
批量下载的图片都是0字节
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?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();[email protected]($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>"; }<br><font color="#e78608">------解决方案--------------------</font><br>直接file_get_content file_put_content<div class="clear"> </div>