ここでは、高さ 435 ピクセル、幅 175 ピクセルの最初の画像と、高さ 200 ピクセル、幅 200 ピクセルの他のすべての画像を検証する例を示します。
$targetPath = $this->registry->DOC_ROOT.'/public/uploads/images/campersite_user_photo/';
if(!is_dir($targetPath))
{
mkdir($targetPath,'0777');
}
$adapter->setDestination($targetPath);
$first = true;
$filecheck = '';
if(isset($asAdminVal['admin_role_id']) && ($asAdminVal['admin_role_id'] == '1' || $asAdminVal['admin_role_id'] == '2'))
{
$photoCount = Model_TblCampersiteUserPhotos::getCamperPhotoCount($this->view->snCampId);
if($photoCount == 0)
{
$j = 1;
foreach ($adapter->getFileInfo() as $fields => $info)
{
if($info['name'] != '' && $first == true)
{
$filecheck = $fields;
}
if($filecheck != '' && $first == true)
{
$form->photo_path->addValidator('ImageSize', false,array('minwidth' => 435,'minheight' => 175,'messages' => array('fileImageSizeWidthTooSmall' => $this->translate->_('msg_camper_banner_image_file_too_width_height_less'),'fileImageSizeHeightTooSmall' => $this->translate->_('msg_camper_banner_image_file_too_width_height_less'))),$fields);
$first = false;
}
else
{
$form->photo_path->addValidator('ImageSize', false,array('minwidth' => 200,'minheight' => 200,'messages' => array('fileImageSizeWidthTooSmall' => $this->translate->_('msg_file_too_small'),'fileImageSizeHeightTooSmall' => $this->translate->_('msg_file_too_small'))),$fields);
}
$fileInfo[$j] = $info;
$j++;
}
}
else
{
$j = 1;
foreach ($adapter->getFileInfo() as $fields => $info)
{
$form->photo_path->addValidator('ImageSize', false,array('minwidth' => 200,'minheight' => 200,'messages' => array('fileImageSizeWidthTooSmall' => $this->translate->_('msg_file_too_small'),'fileImageSizeHeightTooSmall' => $this->translate->_('msg_file_too_small'))),$fields);
$fileInfo[$j] = $info;
$j++;
}
}
}
else
{
$j = 1;
foreach ($adapter->getFileInfo() as $fields => $info)
{
$form->photo_path->addValidator('ImageSize', false,array('minwidth' => 200,'minheight' => 200,'messages' => array('fileImageSizeWidthTooSmall' => $this->translate->_('msg_file_too_small'),'fileImageSizeHeightTooSmall' => $this->translate->_('msg_file_too_small'))),$fields);
$fileInfo[$j] = $info;
$j++;
}
}
フォームを検証するには、以下のコードを記述します。
if($form->isValid($formData))
{
}