protected function buildFileUpload() { $tenantFromIdentity = OpenSKOS_Db_Table_Tenants::fromIdentity(); // We always need tenant for getting icon path. if (null !== $tenantFromIdentity) { $iconUpload = new Zend_Form_Element_File('icon'); $iconUpload->setLabel('Upload a new icon:')->addValidator('Count', false, 1)->setRequired(true); $editorOptions = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('editor'); if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['uploadPath'])) { $iconUpload->setDestination(APPLICATION_PATH . $editorOptions['schemeIcons']['uploadPath'] . '/' . $tenantFromIdentity->code); } else { $iconUpload->setDestination(APPLICATION_PATH . self::DEFAULT_UPLOAD_PATH . '/' . $tenantFromIdentity->code); } if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['allowedExtensions'])) { $iconUpload->addValidator('Extension', false, $editorOptions['schemeIcons']['allowedExtensions']); } else { $iconUpload->addValidator('Extension', false, 'jpg, jpeg, png, gif'); } if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['maxSize'])) { $iconUpload->addValidator('Size', false, $editorOptions['schemeIcons']['maxSize']); $iconUpload->setMaxFileSize($editorOptions['schemeIcons']['maxSize']); } else { $iconUpload->addValidator('Size', false, 2097152); $iconUpload->setMaxFileSize(2097152); } $this->addElement($iconUpload, 'icon'); } return $this; }
public function init() { $this->setMethod('post'); $this->addElementPrefixPath('Ml_Validate', 'Ml/Validate/', Zend_Form_Element::VALIDATE); $this->addElementPrefixPath('Ml_Filter', 'Ml/Filter/', Zend_Form_Element::FILTER); $registry = Zend_Registry::getInstance(); $authedUserInfo = $registry->get('authedUserInfo'); $uploadStatus = $registry->get("uploadStatus"); $this->setAttrib('enctype', 'multipart/form-data'); $this->setMethod('post'); $file = new Zend_Form_Element_File('file'); $file->setLabel('Files:'); $file->setRequired(true); $file->addValidator('Count', false, array('min' => 1, 'max' => 1)); if ($uploadStatus['bandwidth']['remainingbytes'] > 0) { $maxFileSize = $uploadStatus['filesize']['maxbytes']; } else { $maxFileSize = 0; } $file->addValidator('Size', false, $maxFileSize); // hack for not showing 'the file exceeds the defined form size' $file->setMaxFileSize($maxFileSize * 2); /*$file->setMultiFile(1);*/ $this->addElement($file, 'file'); $title = $this->addElement('text', 'title', array('label' => 'Title:', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('validator' => 'StringLength', 'options' => array(1, 100))))); $short = $this->addElement('text', 'short', array('label' => 'Short description:', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('validator' => 'StringLength', 'options' => array(1, 120))))); $description = $this->addElement('textarea', 'description', array('label' => 'Description:', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('validator' => 'StringLength', 'options' => array(1, 4096))))); }
public function init() { $registry = Zend_Registry::getInstance(); $this->addElementPrefixPath('Ml_Validate', 'Ml/Validate/', Zend_Form_Element::VALIDATE); $this->addElementPrefixPath('Ml_Filter', 'Ml/Filter/', Zend_Form_Element::FILTER); $signedUserInfo = $registry->get('signedUserInfo'); $uploadStatus = $registry->get("uploadStatus"); $this->setAttrib('enctype', 'multipart/form-data'); $this->setMethod('post'); $file = new Zend_Form_Element_File('file'); $file->setRequired(false); $file->setLabel('What do you want to share today?'); if ($uploadStatus['bandwidth']['remainingbytes'] > 0) { $maxFileSize = $uploadStatus['filesize']['maxbytes']; } else { $maxFileSize = 0; } $file->addValidator('Size', false, $maxFileSize); $file->setMaxFileSize($maxFileSize); $file->setMultiFile(4); $file->addValidator('Count', false, array('min' => 0, 'max' => 4)); $this->addElement($file, 'file'); $this->addElement(Ml_Model_MagicCookies::formElement()); $this->addElement('submit', 'submitupload', array('label' => 'Upload!', 'class' => 'btn primary')); $this->setAttrib('class', 'form-stacked'); }
public function init() { $this->setAttrib('enctype', 'multipart/form-data'); $this->setMethod('post'); $this->addElementPrefixPath('Ml_Validate', 'Ml/Validate/', Zend_Form_Element::VALIDATE); $this->addElementPrefixPath('Ml_Filter', 'Ml/Filter/', Zend_Form_Element::FILTER); $file = new Zend_Form_Element_File('Image'); $file->setLabel('Choose a picture:'); $file->addValidator('Count', false, 1); $file->addValidator('Size', false, array('max' => '1MB')); $file->setMaxFileSize(2048 * 1024); $file->addValidator('Extension', false, 'jpg,png,gif'); $file->setRequired(false); $file->setOptions(array('ignoreNoFile' => true)); $this->addElement($file, 'Image'); $this->addElement('submit', 'submit', array('label' => 'Submit!', 'class' => 'btn primary')); $this->addElement('submit', 'delete', array('label' => 'Delete current', 'class' => 'btn danger')); $this->setAttrib('class', 'form-stacked'); $this->addElement(Ml_Model_MagicCookies::formElement()); }
public function testAutoGetPostMaxSize() { $this->element->setMaxFileSize(-1); $this->assertNotEquals(-1, $this->element->getMaxFileSize()); }