是否有办法使用此php代码将图像上载限制为400x400px?
if(mandatory_pics_for_jbs == "yes")
{
$args = array(
\'order\' => \'ASC\',
\'orderby\' => \'post_date\',
\'post_type\' => \'attachment\',
\'post_parent\' => $pid,
\'post_mime_type\' => \'image\',
\'numberposts\' => -1,
); $i = 0;
$attachments = get_posts($args);
if(count($attachments) == 0)
{
$adOK = 0; $post_new_error[\'job_img\'] = __(\'You need to upload at least one image for your Design!\');
}
}
SO网友:nakedart
我使用了这段代码,但什么都没发生,也许有一些小细节遗漏了,谢谢你,谁能帮我
$mimes = array( \'image/jpeg\');
if( !in_array( $file[\'type\'], $mimes ) )
return $file;
$image = getimagesize($file[\'tmp_name\']);
$minimum = array(
\'width\' => \'400\',
\'height\' => \'400\'
);
$maximum = array(
\'width\' => \'400\',
\'height\' => \'400\'
);
$image_width = $image[0];
$image_height = $image[1];
if ( $image_width < $minimum[\'width\'] || $image_height < $minimum[\'height\'] ) {
$adOK = 0; $post_new_error[\'job_img\'] = __(\'Image dimension too small\');
}
elseif ( $image_width > $maximum[\'width\'] || $image_height > $maximum[\'height\'] ) {
$adOK = 0; $post_new_error[\'job_img\'] = __(\'Image dimension too big\');
}