emlog531从文章附件获取文章首张图片,如果没有则显示默认图片


function getattachmentimage($logid){

$db = MySql::getInstance();

$sql = "SELECT * FROM ".DB_PREFIX."attachment WHERE blogid=".$logid." AND (`filepath` LIKE '%jpg' OR `filepath` LIKE '%gif' OR `filepath` LIKE '%png') ORDER BY `aid` ASC LIMIT 0,1";

$imgs = $db->query($sql);

$rowimg = $db->fetch_array($imgs);

if($rowimg['filepath']){

$rand_img = BLOG_URL.substr($rowimg['filepath'],3,strlen($rowimg['filepath']));

}else{

$rand_img = TEMPLATE_URL.'images/postdefimg.png';

}

return $rand_img;

}

?>

你可能感兴趣的:(emlog531从文章附件获取文章首张图片,如果没有则显示默认图片)