将代码修改为小于8KB不下载的方式,可以使用curl获取文件大小来判断是否下载。修改后的代码如下:

function save_to_local($weburl,$savepath = '') { $succeed = false;

set_time_limit(0);
if (substr($savepath, -1) != '/') $savepath .= '/';
if (!is_dir($savepath)) @mkdir($savepath, 0777);
$imgurl = 'https://s0.wp.com/mshots/v1/'.$weburl.'?w=730&h=500';
$newpath = $savepath.strtr($weburl,".","_").'.png';
$ch = curl_init($imgurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_exec($ch);
$filesize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
if ($filesize > 0 && $filesize < 8192) {
	$data = get_url_content($imgurl);
	if ($data) {
		$fp = @fopen($newpath, "w");
   		@fwrite($fp, $data);
   		@fclose($fp);
		
		$succeed = true;
	}
}

if ($succeed) {
	return $newpath;
} else {
	return $succeed;
}
把下面的代码修改成小于8KB不下载function save_to_local$weburl$savepath = 	$succeed = false;		set_time_limit0;	if substr$savepath -1 != $savepath = ;	if !is_dir$savepath mkdir$savepath 0777; 			$imgurl = httpimages

原文地址: https://www.cveoy.top/t/topic/iT2t 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录