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); }
/** * Remember file path into session * */ private function saveSession() { $_SESSION[$this->getIdentifier()][self::SESSION_FILE_NAME] = parent::getFileName(); $_SESSION[$this->getIdentifier()][self::SESSION_ORIGINAL_FILE_NAME] = $this->_originalFile; }
/** * 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)); }
public function testEmptyFileName() { $this->element->setTransferAdapter(new Zend_Form_Element_FileTest_MockAdapter()); $this->element->setDestination(dirname(__FILE__)); $this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foo.jpg', $this->element->getFileName()); }
/** * Replace item * * @param string $key * @param Zend_Form_Element_File $file * @return void * @throws InvalidArgumentException */ public function replaceItem($key, \Zend_Form_Element_File $file) { $oldMime = current(explode(';', $this->storage->getMimeType($key))); $newMime = current(explode(';', $file->getMimeType())); if ($oldMime != $newMime && !(in_array($oldMime, self::$equivalentMimeTypes) && in_array($newMime, self::$equivalentMimeTypes))) { throw new \InvalidArgumentException(sprintf('You can only replace a file with a file of the same type. The original file is of type "%s", and the file you uploaded was of type "%s".', $oldMime, $newMime)); } $this->storage->storeItem($key, file_get_contents($file->getFileName())); }
/** * Store and/or delete a file for a file element. * * @uses _deleteOldFile() * @param Zend_Form_Element_File $element */ private function _processFileElement(Zend_Form_Element_File $element) { $elementName = $element->getName(); // set the theme option for the uploaded file to the file name if ($element->getIgnore()) { // set the form value to the old theme option $this->_formValues[$elementName] = $this->_themeOptions[$elementName]; } else { $path = $element->getFileName(); if (empty($path)) { // Make sure null-like values are actually null when saved. $newFile = null; } else { $storage = Zend_Registry::get('storage'); $newFile = basename($path); $storagePath = $storage->getPathByType($newFile, self::THEME_UPLOAD_TYPE); $storage->store($path, $storagePath); } $this->_formValues[$elementName] = $newFile; $this->_deleteOldFile($element); } }
/** * @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; }