问题不在于上传本身,而在于客户端和服务器之间的网络连接。这不是什么在消耗服务器的内存。
当WordPress开始“cruncing”图像时,PHP就开始调整上传图像的大小和裁剪。在这之前,您需要介入并执行一些检查,然后让PHP耗尽您的内存。
使用wp_handle_upload_prefilter
过滤器,您可以挂接一个函数,该函数可以对即将处理的图像执行任何检查:
<?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;
}
?>