有人能帮我编辑代码吗。代码似乎正常工作,但有一个问题,当我在wordpress中添加新插件时,它会提示错误。此代码警报/错误应仅存在于媒体库中,但它似乎也会影响插件页(管理员)。谢谢你
<?php
/* Marc Dingena Utilities
* Test image resolution before image crunch
*/
add_filter(\'wp_handle_upload_prefilter\',\'mdu_validate_image_size\');
function mdu_validate_image_size( $file ) {
$image = getimagesize($file[\'tmp_name\']);
$minimum = array(
\'width\' => \'400\',
\'height\' => \'400\'
);
$maximum = array(
\'width\' => \'2000\',
\'height\' => \'2000\'
);
$image_width = $image[0];
$image_height = $image[1];
$too_small = "Image dimensions are too small. Minimum size is {$minimum[\'width\']} by {$minimum[\'height\']} pixels. Uploaded image is $image_width by $image_height pixels.";
$too_large = "Image dimensions are too large. Maximum size is {$maximum[\'width\']} by {$maximum[\'height\']} pixels. Uploaded image is $image_width by $image_height pixels.";
if ( $image_width < $minimum[\'width\'] || $image_height < $minimum[\'height\'] ) {
// add in the field \'error\' of the $file array the message
$file[\'error\'] = $too_small;
return $file;
}
elseif ( $image_width > $maximum[\'width\'] || $image_height > $maximum[\'height\'] ) {
//add in the field \'error\' of the $file array the message
$file[\'error\'] = $too_large;
return $file;
}
else
return $file;
}
?>
我的代码正确吗?
function mdu_validate_image_size( $file ) {
$image = getimagesize($file[\'tmp_name\']);
if(@!is_array(getimagesize($image))){
$image = true;
}
else {
$image = false;
}
$minimum = array(
\'width\' => \'250\',
\'height\' => \'180\'
);
$maximum = array(
\'width\' => \'250\',
\'height\' => \'180\'
);
$image_width = $image[0];
$image_height = $image[1];
$too_small = "Image dimensions are too small. Minimum size is {$minimum[\'width\']} by {$minimum[\'height\']} pixels. Uploaded image is $image_width by $image_height pixels.";
$too_large = "Image dimensions are too large. Maximum size is {$maximum[\'width\']} by {$maximum[\'height\']} pixels. Uploaded image is $image_width by $image_height pixels.";
if ( $image_width < $minimum[\'width\'] || $image_height < $minimum[\'height\'] ) {
// add in the field \'error\' of the $file array the message
$file[\'error\'] = $too_small;
return $file;
}
elseif ( $image_width > $maximum[\'width\'] || $image_height > $maximum[\'height\'] ) {
//add in the field \'error\' of the $file array the message
$file[\'error\'] = $too_large;
return $file;
}
else
return $file;
}