本文整理汇总了PHP中Zend_Form_Element_File::addFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element_File::addFilter方法的具体用法?PHP Zend_Form_Element_File::addFilter怎么用?PHP Zend_Form_Element_File::addFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_Element_File
的用法示例。
在下文中一共展示了Zend_Form_Element_File::addFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
$this->setAttrib('enctype', 'multipart/form-data');
$renameResize = new Zend_Form_Element_File('renameResize');
$renameResize->setDestination('../upload');
$renameResize->setLabel('Rename before resize');
$renameResize->addFilter('Rename', 'rename-resize');
$renameResize->addFilter(new Skoch_Filter_File_Resize(array('width' => 200, 'height' => 300, 'keepRatio' => true)));
$this->addElement($renameResize);
$resizeRename = new Zend_Form_Element_File('resizeRename');
$resizeRename->setDestination('../upload');
$resizeRename->setLabel('Resize before rename');
$resizeRename->addFilter(new Skoch_Filter_File_Resize(array('width' => 200, 'height' => 300, 'keepRatio' => true)));
$resizeRename->addFilter('Rename', 'resize-rename');
$this->addElement($resizeRename);
$multiResize = new Zend_Form_Element_File('multiResize');
$multiResize->setDestination('../upload');
$multiResize->setLabel('Multiple resizes');
$filterChain = new Zend_Filter();
// Create one big image with at most 600x300 pixel
$filterChain->appendFilter(new Skoch_Filter_File_Resize(array('width' => 600, 'height' => 300, 'keepRatio' => true)));
// Create a medium image with at most 500x200 pixels
$filterChain->appendFilter(new Skoch_Filter_File_Resize(array('directory' => '../upload/medium', 'width' => 500, 'height' => 200, 'keepRatio' => true)));
$multiResize->addFilter('Rename', 'multi-resize');
$multiResize->addFilter($filterChain);
$this->addElement($multiResize);
$renameCrop = new Zend_Form_Element_File('renameCrop');
$renameCrop->setDestination('../upload');
$renameCrop->setLabel('Rename before crop');
$renameCrop->addFilter('Rename', 'rename-crop');
$renameCrop->addFilter(new Skoch_Filter_File_Resize(array('width' => 20, 'height' => 30, 'cropToFit' => true, 'keepRatio' => true)));
$this->addElement($renameCrop);
$submit = new Zend_Form_Element_Submit('submit');
$this->addElement($submit);
}
示例2: getAddContentForm
public function getAddContentForm($submitLabel, $contentTitle = null, $contentDescription = null)
{
$database = Zend_Db_Table::getDefaultAdapter();
$content = $database->select()->from('content')->order('content_id DESC')->query()->fetch();
$imageName = $content['content_id'] + 1;
$form = new Zend_Form();
$form->setMethod('post');
if ($submitLabel == 'Add Content!') {
$form->setAttrib('enctype', 'multipart/form-data');
$image = new Zend_Form_Element_File('foo');
$image->setLabel('Upload an image:')->setDestination('../images');
$image->addFilter('Rename', array('target' => $imageName . '.jpg', 'overwrite' => TRUE));
$image->addValidator('Count', false, 1);
$image->addValidator('Extension', false, 'jpg,png,gif');
$form->addElement($image, 'foo');
}
$title = $form->createElement('text', 'title');
$title->setRequired(true);
$title->setValue($contentTitle);
$title->setLabel('Title');
$form->addElement($title);
$description = $form->createElement('textarea', 'description', array('rows' => 10));
$description->setRequired(true);
$description->setValue($contentDescription);
$description->setLabel('Description');
$form->addElement($description);
$form->addElement('submit', 'submit', array('label' => $submitLabel));
return $form;
}
示例3: init
public function init()
{
$media_library_model = new Cms_Model_MediaLibraries();
$media_library = $media_library_model->getByPath($this->_attribs['media_library_path']);
$title = new Zend_Form_Element_Text('title');
$title->setLabel('Title');
$title->setRequired(true);
$title->addFilter('StringTrim');
$title->addValidator('Alnum', false, array('allowWhiteSpace' => true));
$this->addElement($title);
$description = new Zend_Form_Element_Textarea('description');
$description->setLabel('Description');
$description->addFilter('StringTrim');
$description->addValidator('Alnum', false, array('allowWhiteSpace' => true));
$this->addElement($description);
$original = new Zend_Form_Element_File('original');
$original->addValidator('Count', false, 1);
$original->addValidator('Extension', false, 'jpeg,jpg,png');
$original->addFilter('Rename', $this->_attribs['file_name']);
$original->setDestination(My_Utilities::getUploadMediaPathDiffSizes($this->_attribs['file_name'], $this->_attribs['media_library_path'], 'original'));
$original->setLabel('Image:');
$this->addElement($original);
$submit = new Zend_Form_Element_Submit('save');
$submit->setAttrib('class', 'btn btn-primary');
$submit->setLabel('Potvrdi');
$this->setAction('')->setMethod('post')->addElement($submit);
$cancel = new Zend_Form_Element_Button('cancel');
$cancel->setLabel('Cancel');
$cancel->setAttrib('class', 'btn btn-gold')->setAttrib('style', 'color:black');
$cancel->setAttrib("onClick", "window.location = window.location.origin+'/cms/medias/index/library_id/" . $media_library->id . "'");
$this->addElement($cancel);
}
示例4: __construct
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('report');
$image = new Zend_Form_Element_File('image');
//$image->setDestination(PUBLIC_PATH . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . 'qq' . DIRECTORY_SEPARATOR);
$fileName = $options[0] . '_' . $options[1] . '_' . date('Y-m-d_H:i:s') . '.png';
$config = Zend_Registry::get('config');
$image->addFilter('Rename', array('target' => $config->framework->upload_dir . DIRECTORY_SEPARATOR . 'report_images' . DIRECTORY_SEPARATOR . $fileName, 'overwrite' => true));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel($this->getView()->translate("Submit_button"));
$this->addElements(array($image, $submit));
}
示例5: init
public function init()
{
$this->setAction('')->setMethod('post');
$filename = time() . rand(1000, 9999);
$ava = new Zend_Form_Element_File('ava');
$ava->setAttrib('width', 120);
$ava->setLabel('Upload avatar (75x75 px)')->setDestination('avatars');
$ava->addFilter('Rename', sprintf('ava%s.jpg', $filename, true));
$ava->addValidator('Size', false, '204800')->addValidator('Extension', false, 'jpg,png,gif')->addValidator('ImageSize', false, array('minwidth' => 1, 'minheight' => 1, 'maxwidth' => 75, 'maxheight' => 75));
$submit = new Zend_Form_Element_Submit('uploadavatar');
$submit->setLabel("Upload");
$this->addElements(array($ava, $submit));
return $this;
}
示例6: init
public function init()
{
// profissional_beleza_nome
$profissional_beleza_nome = new Zend_Form_Element_Text("profissional_beleza_nome");
$profissional_beleza_nome->setLabel("Nome: ");
$profissional_beleza_nome->setAttribs(array('class' => 'form-control'));
$profissional_beleza_nome->setRequired();
$profissional_beleza_nome->setDecorators(App_Forms_Decorators::$simpleElementDecorators);
// profissional_beleza_email
$profissional_beleza_email = new Zend_Form_Element_Text("profissional_beleza_email");
$profissional_beleza_email->setLabel("E-mail: ");
$profissional_beleza_email->setValidators(array('EmailAddress'));
$profissional_beleza_email->addValidator(new App_Validate_ProfissionalBeleza());
$profissional_beleza_email->setAttribs(array('class' => 'form-control'));
$profissional_beleza_email->setRequired();
$profissional_beleza_email->setDecorators(App_Forms_Decorators::$simpleElementDecorators);
/**
* profisional_beleza_sexo
*/
$profissional_beleza_sexo = new Zend_Form_Element_Radio("profissional_beleza_sexo");
$profissional_beleza_sexo->setLabel("Sexo:");
$profissional_beleza_sexo->setRequired();
$profissional_beleza_sexo->setDecorators(App_Forms_Decorators::$checkboxElementDecorators);
$profissional_beleza_sexo->setMultiOptions(array('M' => ' Masculino', 'F' => ' Feminino'));
// profissional_beleza_avatar
$profissional_beleza_avatar = new Zend_Form_Element_File("profissional_beleza_avatar");
$profissional_beleza_avatar->setLabel(" \n Foto: \n ");
$profissional_beleza_avatar->addDecorators(App_Forms_Decorators::$ElementDecoratorFile);
$profissional_beleza_avatar->setAttribs(array('class' => 'filestyle', 'data-buttonText' => 'Selecione a foto', 'data-iconName' => 'fa fa-user'));
$profissional_beleza_avatar->setRequired();
$profissional_beleza_avatar->setDestination(Zend_Registry::get('config')->profissional->avatar->path);
$profissional_beleza_avatar->addValidators(array(array('Extension', false, 'jpg,jpeg,png')));
$profissional_beleza_avatar->addFilter(new Skoch_Filter_File_Resize(array('width' => 160, 'keepRatio' => true)));
// especialidade_id
$especialidade_id = new Zend_Form_Element_MultiCheckbox("especialidade_id");
$especialidade_id->setLabel("Selecione as especialidades: ");
$especialidade_id->setAttribs(array('class' => ''));
$especialidade_id->setRequired();
$especialidade_id->setDecorators(App_Forms_Decorators::$checkboxElementDecorators);
$especialidade_id->setSeparator(' ');
$especialidade_id->setMultiOptions($this->getEspecialidades());
// addElements
$this->addElements(array($profissional_beleza_nome, $profissional_beleza_email, $profissional_beleza_sexo, $profissional_beleza_avatar, $especialidade_id));
parent::init();
}
示例7: getUploadForm
public static function getUploadForm()
{
$form = new Zend_Form();
$form->setAction('')->setMethod(Zend_Form::METHOD_POST)->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);
$form->setDecorators(array(array('ViewScript', array('viewScript' => 'import/uploadForm.phtml')), 'Errors'));
$f = new Zend_Form_Element_File('file');
//, array ('label' => 'Веберіть файл пакету') );
// $f->setAttrib ( 'style', 'width: 600px' );
$f->setRequired();
$f->addValidator('Count', false, 1);
// $f->addValidator ( 'Size', false, 204800 );
$f->addValidator('Extension', false, 'xls');
$cfg = Zend_Registry::get('cfg');
$target = $cfg['temp']['path'] . Zend_Auth::getInstance()->getIdentity()->NODEID . '.xls';
$f->addFilter('Rename', array('target' => $target, 'overwrite' => 'true'));
$form->addElement($f);
$e = new Zend_Form_Element_Submit('submit', array('label' => 'Завантажити'));
$form->addElement($e);
return $form;
}
示例8: init
public function init()
{
$user = Zend_Auth::getInstance()->getIdentity();
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email')->setRequired(true)->addValidator('EmailAddress')->setAttrib("class", "form-control")->setAttrib("style", "width:200px")->addErrorMessage('Email address not valid');
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password')->setAttrib("class", "form-control")->setAttrib("style", "width:200px")->setAttrib('autocomplete', 'off')->setRequired(true);
$name = new Zend_Form_Element_Text('first_name');
$name->setLabel('First name')->setAttrib("class", "form-control")->setAttrib("style", "width:200px")->setRequired(true);
$lastname = new Zend_Form_Element_Text('last_name');
$lastname->setLabel('Last name')->setAttrib("class", "form-control")->setAttrib("style", "width:200px")->setRequired(true);
$role_name = new Zend_Form_Element_Select('role_id');
$role_name->setLabel('Account type')->setRequired(true)->setRegisterInArrayValidator(false);
$role_name->setAttrib("class", "select2")->setAttrib("style", "width:200px");
$roles_table = new Admin_Model_Roles();
foreach ($roles_table->getAll() as $v) {
$role_name->addMultiOption($v->id, $v->name);
}
$img = new Zend_Form_Element_File('image');
$img->setDestination(WEB_PATH . Zend_Registry::get('upload_profile_img_path'));
$img->addValidator('Count', false, 1);
$img->addValidator('Extension', false, 'jpeg,jpg,png,gif');
if ($img->getFileName()) {
$new_name = md5(rand(1000, 10000) . time() . $img->getFileName()) . "." . preg_replace('/^.*\\.([^.]+)$/D', '$1', $img->getFileName());
$img->addFilter('Rename', $new_name);
}
$img->setLabel('Image');
$is_active = new Zend_Form_Element_Checkbox("is_active");
$is_active->setLabel('Active')->setAttrib("class", "icheckbox_square");
$cancel = new Zend_Form_Element_Button('cancel');
$cancel->setLabel('Cancel');
$cancel->setAttrib('class', 'btn btn-gold')->setAttrib('style', 'color:black');
$cancel->setAttrib("onClick", "window.location = window.location.origin+'/admin/admin-users/'");
$submit = new Zend_Form_Element_Submit('save');
$submit->setAttrib('class', 'btn btn-primary');
$submit->setLabel('Confirm');
$this->setAction('')->setMethod('post')->addElement($email)->addElement($password)->addElement($name)->addElement($lastname)->addElement($role_name)->addElement($img)->addElement($is_active)->addElement($cancel)->addElement($submit);
}
示例9: __construct
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('phoneForm');
$phonenum = new Zend_Form_Element_Text('phoneNum');
$phonenum->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$phonenum->setAttribs(array('onblur' => 'searchname();'));
$image = new Zend_Form_Element_File('image');
//$image->setDestination(PUBLIC_PATH . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . 'qq' . DIRECTORY_SEPARATOR);
$fileName = date('Y-m-d_H:i:s') . '.png';
$config = Zend_Registry::get('config');
$image->addFilter('Rename', array('target' => $config->framework->upload_dir . DIRECTORY_SEPARATOR . 'conversation_images' . DIRECTORY_SEPARATOR . $fileName, 'overwrite' => true));
$consumername = new Zend_Form_Element_Text('consumerName');
$consumername->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$content = new Zend_Form_Element_Textarea('content');
$content->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$evaluation = new Zend_Form_Element_Textarea('evaluation');
$evaluation->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$duration = new Zend_Form_Element_Text('duration');
$duration->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('发 送');
$this->addElements(array($phonenum, $consumername, $content, $evaluation, $duration, $submit, $image));
}
示例10: __construct
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('qqForm');
$mediafrom = new Zend_Form_Element_Select('mediafrom');
$mediafrom->setMultiOptions(array('qq' => 'qq', '开心' => '开心', '校内' => '校内', '19楼' => '19楼'));
$mediafrom->setValue('qq');
$image = new Zend_Form_Element_File('image');
//$image->setDestination(PUBLIC_PATH . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . 'qq' . DIRECTORY_SEPARATOR);
$fileName = date('Y-m-d_H:i:s') . '.png';
$config = Zend_Registry::get('config');
$image->addFilter('Rename', array('target' => $config->framework->upload_dir . DIRECTORY_SEPARATOR . 'conversation_images' . DIRECTORY_SEPARATOR . $fileName, 'overwrite' => true));
$qqnum = new Zend_Form_Element_Text('qqNum');
$qqnum->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$consumername = new Zend_Form_Element_Text('consumerName');
$consumername->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$content = new Zend_Form_Element_Textarea('content');
$content->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$evaluation = new Zend_Form_Element_Textarea('evaluation');
$evaluation->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel("发 送");
$this->addElements(array($image, $mediafrom, $qqnum, $consumername, $content, $evaluation, $submit));
}
示例11: _uploadFiles
private function _uploadFiles($uploadDir = '')
{
if (!is_dir($uploadDir)) {
@mkdir($uploadDir);
chmod($uploadDir, 0777);
}
//upload thumb image
for ($i = 1; $i <= 6; $i++) {
$image = new Zend_Form_Element_File('images' . $i);
$image->setDestination($uploadDir);
$image->addValidator('Count', false, 1);
$image->addValidator('Extension', false, 'jpeg,jpg,png,gif');
$image->addFilter('Rename', array('target' => $uploadDir . DIRECTORY_SEPARATOR . $i . '.jpg', 'overwrite' => true));
$image->receive();
}
// //uploads images for gallery
// $images = new Zend_Form_Element_File( 'images' );
// $images->setDestination( $uploadDir );
// //$element->addValidator ( 'Size', false, 512000 );
// $images->addValidator( 'Extension', false, 'jpeg,jpg,png,gif' );
// $images->setMultiFile( count( $_POST ['images'] ) );
// $images->receive();
// return $images->getFileName( null, false );
}
示例12: init
public function init()
{
$this->setMethod('post')->setAttrib('id', 'frmTest')->setAttrib('enctype', 'multipart/form-data');
// Elemento: Nombre
$e = new Zend_Form_Element_Text('nombre');
$e->setLabel('Nombre');
$e->setFilters(array('StringToLower'));
$this->addElement($e);
// Elemento: activo
$e = new Zend_Form_Element_Checkbox('activo');
$e->setLabel('Activo');
$this->addElement($e);
// Elemento: activo2
$e = new Zend_Form_Element_Radio('activo2');
$e->setLabel('Activo2');
$_cat = new Application_Model_Categoria();
$values = $_cat->getComboValues();
$e->setMultiOptions($values);
$e->setValue(array_rand($values));
$v = new Zend_Validate_InArray(array_keys($values));
$this->addElement($e);
$e = new Zend_Form_Element_File('imagen');
$e->setLabel('Upload an image:');
$e->setDestination(APPLICATION_PATH . '/../public/uploads/');
$f = new Zend_Filter_File_Rename(array('target' => '123.jpg'));
// Renombrar archivo
$e->addFilter($f);
$e->addValidator('Count', false, 1);
// Solo 1 archivo
$e->addValidator('Size', false, 102400);
// limite de 100K
$e->addValidator('Extension', false, 'jpg,png,gif');
// solo JPEG, PNG, and GIFs
$this->addElement($e);
$this->addElement('submit', 'Enviar');
}
示例13: _addFileRenameFilter
/**
* Add filter to rename uploaded files for themes.
*
* @param Zend_Form_Element_File $element
*/
private function _addFileRenameFilter($element)
{
$elementName = $element->getName();
$fileName = $element->getFileName(null, false);
$uploadedFileName = Theme::getUploadedFileName($this->getThemeName(), $elementName, $fileName);
$uploadedFilePath = $element->getDestination() . '/' . $uploadedFileName;
$element->addFilter('Rename', array('target' => $uploadedFilePath, 'overwrite' => true));
}
示例14: addFile
public function addFile($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
{
$options = func_get_args();
$options = \MUtil_Ra::pairs($options, 1);
$options = $this->_mergeOptions($name, $options, self::DISPLAY_OPTIONS, self::FILE_OPTIONS, self::TEXT_OPTIONS);
$filename = $this->_moveOption('filename', $options);
$count = $this->_moveOption('count', $options);
$size = $this->_moveOption('size', $options);
$extension = $this->_moveOption('extension', $options);
$element = new \Zend_Form_Element_File($name, $options);
if ($filename) {
$count = 1;
// When
// 1) an extension filter was defined,
// 2) it concerns a single extension and
// 3) $filename does not have an extension
// then add the extension to the name.
if ($extension && false === strpos($extension, ',') && false === strpos($name, '.')) {
$filename .= '.' . $extension;
}
$element->addFilter(new \Zend_Filter_File_Rename(array('target' => $filename, 'overwrite' => true)));
}
if ($count) {
$element->addValidator('Count', false, $count);
}
if ($size) {
$element->addValidator('Size', false, $size);
}
if ($extension) {
$element->addValidator('Extension', false, $extension);
// Now set a custom validation message telling what extensions are allowed
$validator = $element->getValidator('Extension');
$validator->setMessage('Only %extension% files are accepted.', \Zend_Validate_File_Extension::FALSE_EXTENSION);
}
return $this->_addToForm($name, $element);
}
示例15: saveUploadFile
/**
* @param Zend_Form_Element_File $element
* @param $item mixed
* @return mixed
* @throws Exception
*
*/
public function saveUploadFile(Zend_Form_Element_File $element, $item)
{
$uploadPath = $element->getAttrib('data-upload') . '/' . $item->getId();
if (!file_exists(APPLICATION_ROOT . $uploadPath)) {
mkdir(APPLICATION_ROOT . $uploadPath, 0755, true);
}
//$element->setDestination(APPLICATION_ROOT.$uploadPath);
$fileName = $element->getFileName(null, false);
$path = APPLICATION_ROOT . $uploadPath . '/' . $fileName;
$path = iconv('utf-8', 'cp1251', $path);
try {
$element->addFilter('Rename', array('target' => $path, 'overwrite' => true));
$element->receive();
$item->setOptions(array($element->getAttrib('data-input') => $uploadPath . '/' . $fileName));
$this->getModelMapper()->save($item);
} catch (Zend_File_Transfer_Exception $e) {
throw new Exception('Bad image data: ' . $e->getMessage());
}
return $item;
}