批量下载的图片都是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();
$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 = <a style="color:#f60; text-decoration:underline;" title="mysql" href="https://www.php.cn/zt/15713.html" target="_blank">mysql</a>_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>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号