在尝试验证图片上传时,我似乎无法弄清楚此错误的原因
$imagevalidate = Validate::factory($_FILES);
$imagevalidate->rules($_FILES['profile_picture'], array(
'Upload::valid' => array(),
'Upload::not_empty' => array(),
'Upload::type' => array(
'Upload::type' => array(
'jpg',
'png',
'gif'
)
),
'Upload::size' => array(
'1M'
)
));
if ($imagevalidate->check()) {
$picture = Upload::save($_FILES['profile_picture']);
Image::factory($picture)->resize(200, 200, Image::WIDTH)->save();
$profile->profile_picture = basename($picture);
} else {
$errors = $imagevalidate()->errors('profile/edit');
}
我收到此错误ErrorException [警告]:isset中的非法偏移类型或空
答案 0 :(得分:2)
在3.2示例传递中:
$array = Validation::factory($_FILES);
$array->rule('file', 'Upload::size', array(':value', '900KiB'));
$array->rule('file', 'Upload::type', array(':value', array('jpg', 'png', 'gif')));
$array->rule('file', 'Upload::image', array(':value', array(640, 480)));
$array->rule('file', 'Upload::valid');
if($array->check())
{
if(Upload::save($_FILES['file']))
echo 'uploaded';
}
else
{
echo Debug::vars($array->errors('profile/edit'));
}
消息文件:
return array(
'file' => array(
'Upload::type' => 'blabla',
'Upload::size' => 'blabla',
'Upload::image' => 'blablan',
'Upload::valid' => 'blablabla'
),
);
联合国..希望对您有所帮助:)