在服务器上查看错误日志时,我不断看到错误:
PHP Warning: Division by zero in /public_html/wp-content/themes/sass-wordpress-bootstrap-master/image.php on line 95
以下是发生错误的代码:
$imgmeta = wp_get_attachment_metadata( $id );
// Convert the shutter speed retrieve from database to fraction
if ((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']) > 1)
{
if ((number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1)) == 1.3
or number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1) == 1.5
or number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1) == 1.6
or number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1) == 2.5){
$pshutter = "1/" . number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1, \'.\', \'\') . " second";
}
else{
$pshutter = "1/" . number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 0, \'.\', \'\') . " second";
}
}
else{
$pshutter = $imgmeta[\'image_meta\'][\'shutter_speed\'] . " seconds";
}
我真的不知道什么时候会叫它。机器人是否会触发此错误?
SO网友:brandozz
该错误是在图像附件页上生成的,因此这很可能是一个机器人。但在快门速度转换为分数之前,我添加了一个检查:
$imgmeta = wp_get_attachment_metadata( $id );
$imgShutter = $imgmeta[\'image_meta\'][\'shutter_speed\'];
// Convert the shutter speed retrieve from database to fraction
if ($imgShutter > 0) {
if ((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']) > 1)
{
if ((number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1)) == 1.3
or number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1) == 1.5
or number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1) == 1.6
or number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1) == 2.5){
$pshutter = "1/" . number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 1, \'.\', \'\') . " second";
}
else{
$pshutter = "1/" . number_format((1 / $imgmeta[\'image_meta\'][\'shutter_speed\']), 0, \'.\', \'\') . " second";
}
}
else{
$pshutter = $imgmeta[\'image_meta\'][\'shutter_speed\'] . " seconds";
}
}