我需要通过media box检查要上载的图像的分辨率,然后将其上载到自定义目录。
作为起点,我使用了How Can I Organize the Uploads Folder by Slug (or ID, or FileType, or Author)?
其中一部分是这样的:
function wpse_25894_custom_upload_dir($path)
{
$use_default_dir = ( isset($_REQUEST[\'post_id\'] ) && $_REQUEST[\'post_id\'] == 0 ) ? true : false;
if( !empty( $path[\'error\'] ) || $use_default_dir )
return $path; //error or uploading not from a post/page/cpt
//THIS LINE PRODUCE ERROR. HERE I NEED TO GET WIDTH AND HEIGHT OF IMAGE I WANT TO UPLOAD
list($width, $height) = getimagesize($path.\'/\'.$_POST[\'name\']);
$customdir = \'/\'.$width.\'x\'.$height; //uplaod folder will be for example \'640x480\'
$path[\'path\'] = str_replace($path[\'subdir\'], \'\', $path[\'path\']); //remove default subdir (year/month)
$path[\'url\'] = str_replace($path[\'subdir\'], \'\', $path[\'url\']);
$path[\'subdir\'] = $customdir;
$path[\'path\'] .= $customdir;
$path[\'url\'] .= $customdir;
return $path;
}
$_POST[\'name\']
包含图像的文件名,如“myimage”。jpg’。