本文整理汇总了PHP中Zend_File_Transfer_Adapter_Http::addValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_File_Transfer_Adapter_Http::addValidator方法的具体用法?PHP Zend_File_Transfer_Adapter_Http::addValidator怎么用?PHP Zend_File_Transfer_Adapter_Http::addValidator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_File_Transfer_Adapter_Http
的用法示例。
在下文中一共展示了Zend_File_Transfer_Adapter_Http::addValidator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($arrParam = array(), $options = null)
{
//////////////////////////////////
//Kiem tra Name /////////////
//////////////////////////////////
if ($arrParam['action'] == 'add') {
$options = array('table' => 'da_album', 'field' => 'album_name');
} elseif ($arrParam['action'] == 'edit') {
$options = array('table' => 'da_album', 'field' => 'album_name', 'exclude' => array('field' => 'id', 'value' => $arrParam['id']));
}
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(3, 100), true);
if (!$validator->isValid($arrParam['album_name'])) {
$message = $validator->getMessages();
$this->_messageError['album_name'] = 'Tên album: ' . current($message);
$arrParam['album_name'] = '';
}
//////////////////////////////////
//Kiem tra Picture small ///////////
//////////////////////////////////
$upload = new Zend_File_Transfer_Adapter_Http();
$fileInfo = $upload->getFileInfo('picture');
$fileName = $fileInfo['picture']['name'];
if (!empty($fileName)) {
$upload->addValidator('Extension', true, array('jpg', 'gif', 'png'), 'picture');
$upload->addValidator('Size', true, array('min' => '2KB', 'max' => '1000KB'), 'picture');
if (!$upload->isValid('picture')) {
$message = $upload->getMessages();
$this->_messageError['picture'] = 'Hình ảnh đại diện: ' . current($message);
}
}
//////////////////////////////////
//Kiem tra Order /////////////
//////////////////////////////////
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_StringLength(1, 10), true)->addValidator(new Zend_Validate_Digits(), true);
if (!$validator->isValid($arrParam['order'])) {
$message = $validator->getMessages();
$this->_messageError['order'] = 'Sắp xếp: ' . current($message);
$arrParam['order'] = '';
}
//////////////////////////////////
//Kiem tra Status /////////////
//////////////////////////////////
if (empty($arrParam['status']) || !isset($arrParam['status'])) {
$arrParam['status'] = 0;
}
//========================================
// TRUYEN CAC GIA TRI DUNG VAO MANG $_arrData
//========================================
$this->_arrData = $arrParam;
}
示例2: browseAction
/**
* Provides an image browser feature for the rich text editor
*
* @return void
*/
public function browseAction()
{
$params = Zend_Registry::get('params');
// This is displayed inside the editor - so we need set a blank layout (no header/footer)
$this->_helper->layout->setLayout('popup');
$gallery = new Datasource_Cms_Gallery();
$categoryID = $this->getRequest()->getParam('cid');
$editorFuncNum = $this->getRequest()->getParam('CKEditorFuncNum');
if ($this->getRequest()->isPost()) {
// A new image has been sent - handle it
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination($params->cms->imageUploadPath);
$upload->addValidator('Extension', false, 'jpg,jpeg,png,gif');
$upload->addValidator('Count', false, 1);
$upload->addValidator('Size', false, 10240000);
if ($upload->receive()) {
// File has been uploaded succesfully
$this->view->uploadSuccess = true;
$imageFilename = $upload->getFileName(null, false);
$imageLocation = $upload->getFileName();
list($imageWidth, $imageHeight) = getimagesize($imageLocation);
$imageID = $gallery->addNew(0, $imageFilename, $imageWidth, $imageHeight);
// Resize and save a few pr
$cmsImage = new Application_Cms_Image();
if ($imageWidth > $imageHeight) {
$cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/200_' . $imageFilename, 200, null);
$cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/400_' . $imageFilename, 400, null);
} else {
$cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/200_' . $imageFilename, null, 150);
$cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/400_' . $imageFilename, null, 400);
}
$this->_helper->getHelper('FlashMessenger')->addMessage(array('deleted' => true));
// $this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/images/edit?id='. $imageID); // Forward to image editor
$this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/images/browse?CKEditorFuncNum=' . $editorFuncNum);
} else {
// An error occurred - deal with the error messages
$errorMessages = $upload->getMessages();
}
} else {
// No image uploaded - show the gallery
if (!$categoryID) {
$categoryID = 0;
}
$imageList = $gallery->getImagesByCategoryID($categoryID);
$this->view->imageList = $this->view->partialLoop('partials/image-browser-image.phtml', $imageList);
$this->view->editorFuncNum = $editorFuncNum;
}
}
示例3: _uploadPlugin
private function _uploadPlugin()
{
$this->_uploadHandler->addValidator('Extension', false, 'zip');
if ($this->_checkMime) {
$this->_uploadHandler->addValidator(new Validators_MimeType(array('application/zip')), false);
}
$pluginArchive = $this->_uploadHandler->getFileInfo();
if (!$this->_uploadHandler->isValid()) {
return array('error' => true);
}
$destination = $this->_uploadHandler->getDestination();
$zip = new ZipArchive();
$zip->open($pluginArchive['file']['tmp_name']);
$unzipped = $zip->extractTo($destination);
if ($unzipped !== true) {
return array('name' => $pluginArchive['file']['name'], 'error' => 'Can\'t extract zip file to tmp directory');
}
$pluginName = str_replace('.zip', '', $pluginArchive['file']['name']);
$validateMessage = $this->_validatePlugin($pluginName);
$miscConfig = Zend_Registry::get('misc');
if ($validateMessage === true) {
$destinationDir = $this->_websiteConfig['path'] . $miscConfig['pluginsPath'];
if (is_dir($destinationDir . $pluginName)) {
Tools_Filesystem_Tools::deleteDir($destinationDir . $pluginName);
}
$res = $zip->extractTo($destinationDir);
$zip->close();
Tools_Filesystem_Tools::deleteDir($destination . '/' . $pluginName);
} else {
$zip->close();
return array('name' => $pluginArchive['file']['name'], 'error' => $validateMessage);
}
return array('error' => false, 'name' => $pluginArchive['file']['name'], 'type' => $pluginArchive['file']['type'], 'size' => $pluginArchive['file']['size'], 'pluginname' => $pluginName);
}
示例4: addValidator
/**
* Use the Zend Framework adapter to handle validation instead of the
* built-in _validateFile() method.
*
* @see Omeka_File_Ingest_AbstractIngest::_validateFile()
* @param Zend_Validate_Interface $validator
* @return void
*/
public function addValidator(Zend_Validate_Interface $validator)
{
if (!$this->_adapter) {
$this->_buildAdapter();
}
$this->_adapter->addValidator($validator);
}
示例5: uploadImage
public function uploadImage($scope)
{
// create an instance of class Zend_File_Transfer_Adapter_Http
// and add validator
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->addValidator('ImageSize', true, $this->_imageSize);
$adapter->addValidator('Size', true, self::MAX_FILE_SIZE);
// if image can be uploaded
if ($adapter->isUploaded($scope)) {
//validate image
if (!$adapter->isValid($scope)) {
Mage::throwException(Mage::helper('ab_adverboard')->__('Uploaded image is not valid'));
}
// upload image
$upload = new Varien_File_Uploader($scope);
$upload->setAllowCreateFolders(true);
$upload->setAllowedExtensions($this->_allowedExtensions);
$upload->setAllowRenameFiles(false);
$upload->setFilesDispersion(false);
if ($upload->save($this->getBaseDir(), $_FILES['image']['name'])) {
return $upload->getUploadedFileName();
}
}
return false;
}
示例6: uploadAction
public function uploadAction()
{
$project_id = $this->_request->getParam('id');
//Validate that project belongs to user here.
$project_helper = $this->_helper->Projects;
if ($project_helper->isOwner($this->user_session->id, $project_id, $this->project_model)) {
$adapter = new Zend_File_Transfer_Adapter_Http();
foreach ($adapter->getFileInfo() as $key => $file) {
//Get extension
$path = split("[/\\.]", $file['name']);
$ext = end($path);
try {
$adapter->addValidator('Extension', false, array('extension' => 'jpg,gif,png', 'case' => true));
//Should probably use the array method below to enable overwriting
$new_name = md5(rand()) . '-' . $project_id . '.' . $ext;
//Add rename filter
$adapter->addFilter('Rename', UPLOAD_PATH . $new_name);
} catch (Zend_File_Transfer_Exception $e) {
die($e->getMessage());
}
try {
//Store
if ($adapter->receive($file['name'])) {
$this->image_model->addOne($project_id, $new_name, $key);
}
} catch (Zend_File_Transfer_Exception $e) {
die($e->getMessage());
}
}
header("Location: /account/project/id/{$project_id}");
} else {
header("Location: /account");
}
}
示例7: handleFileTransfer
/**
* handleFileTransfer
* @author Thomas Schedler <tsh@massiveart.com>
*/
private function handleFileTransfer()
{
$this->objUpload = new Zend_File_Transfer_Adapter_Http();
$this->objUpload->setOptions(array('useByteString' => false));
/**
* validators for upload of media
*/
$arrExcludedExtensions = $this->core->sysConfig->upload->excluded_extensions->extension->toArray();
$this->objUpload->addValidator('Size', false, array('min' => 1, 'max' => $this->core->sysConfig->upload->max_filesize));
$this->objUpload->addValidator('ExcludeExtension', false, $arrExcludedExtensions);
/**
* check if medium is uploaded
*/
if (!$this->objUpload->isUploaded(self::UPLOAD_FIELD)) {
$this->core->logger->warn('isUploaded: ' . implode('\\n', $this->objUpload->getMessages()));
throw new Exception('File is not uploaded!');
}
/**
* check if upload is valid
*/
if (!$this->objUpload->isValid(self::UPLOAD_FIELD)) {
$this->core->logger->warn('isValid: ' . implode('\\n', $this->objUpload->getMessages()));
throw new Exception('Uploaded file is not valid!');
}
}
示例8: configAction
function configAction()
{
// When the form is submitted
$form_mess = "";
if (isset($_POST['confName'])) {
$form_mess = $this->updateConfig($_POST, $this->db_v1, $this->view, $this->session);
$this->config_v1 = GetConfig($this->db_v1);
// Check whether the logo file has been transmitted
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination('images/');
$adapter->addValidator('IsImage', false);
if ($adapter->receive()) {
$name = $adapter->getFileName('logo_file');
//récupérer le nom du fichier sans avoir tout le chemin
$name = basename($name);
$this->db_v1->execRequete("UPDATE Config SET logo_file='{$name}'");
}
$config = new Config();
$this->config = $config->fetchAll()->current();
$this->config->putInView($this->view);
$registry = Zend_registry::getInstance();
$registry->set("Config", $this->config);
}
$this->view->config_message = $form_mess;
$this->instantiateConfigVars($this->config_v1, $this->view);
$this->view->setFile("content", "config.xml");
$this->view->setFile("form_config", "form_config.xml");
$form_mess = "";
$this->view->messages = $form_mess;
// N.B: the config values ar eput in the views by the Myreview controller
echo $this->view->render("layout");
}
示例9: imageAction
public function imageAction()
{
if ($this->getRequest()->isPost()) {
$upload = new Zend_File_Transfer_Adapter_Http();
$dirs = array('image' => array('gif', 'jpg', 'jpeg', 'png'), 'flash' => array('swf', 'flv'));
$dir = $this->_getParam('dir');
if (!isset($dirs[$dir])) {
$this->_alert('上传类型出错!');
}
$savePath = UPLOAD_PATH . DS . $dir;
//检查文件大小
$upload->addValidator('Size', false, 500000);
if (false == $upload->isValid()) {
$this->_alert('上传文件大小超过500KB限制。');
}
//检查目录
if (@is_dir($savePath) === false) {
$this->_alert('上传目录不存在。');
}
//检查目录写权限
if (@is_writable($savePath) === false) {
$this->_alert('上传目录没有写权限。');
}
//获得文件类型
$upload->addValidator('Extension', false, $dirs[$dir]);
if (false == $upload->isValid()) {
$this->_alert('只能上传' . implode('、', $dirs[$dir]) . '文件类型');
}
//设置保存的Path
$upload->setDestination($savePath);
//设置新的文件名
$fileInfo = $upload->getFileInfo();
$tmpFile = $fileInfo['imgFile']['name'];
$extension = explode('.', $tmpFile);
$extension = array_pop($extension);
$newFile = md5($tmpFile . uniqid()) . '.' . $extension;
$upload->addFilter('Rename', array('target' => $savePath . DS . $newFile, 'overwrite' => true));
//保存文件
$upload->receive();
//返回文件url
echo Zend_Json::encode(array('error' => 0, 'url' => $this->view->baseUrl() . '/uploads/image/' . $newFile));
exit;
} else {
$this->_alert('请选择文件。');
exit;
}
}
示例10: generateUploadObject
/**
* Returns an upload object based on the global accessible $_FILES variable.
* The returned upload will be pre-configured with a validator for the
* system's max upload size and the count of allowed simultaneusly uploads
* set to 1.
*
* @return Zend_File_Transfer_Adapter_Http
*/
public function generateUploadObject()
{
// build up upload
$upload = new Zend_File_Transfer_Adapter_Http();
// assign and check validators
$upload->addValidator('Size', true, $this->_getUploadMaxFileSize());
$upload->addValidator('Count', true, array('min' => 1, 'max' => 1));
return $upload;
}
示例11: indexAction
/**
* indexAction
* @author Thomas Schedler <tsh@massiveart.com>
* @version 1.0
*/
public function indexAction()
{
try {
$this->core->logger->debug('media->controllers->UploadController->indexAction()');
$this->objUpload = new Zend_File_Transfer_Adapter_Http();
/**
* validators for upload of media
*/
$arrExcludedExtensions = $this->core->sysConfig->upload->excluded_extensions->extension->toArray();
$this->objUpload->addValidator('Size', false, array('min' => 1, 'max' => $this->core->sysConfig->upload->max_filesize));
$this->objUpload->addValidator('ExcludeExtension', false, $arrExcludedExtensions);
/**
* check if medium is uploaded
*/
if (!$this->objUpload->isUploaded(self::UPLOAD_FIELD)) {
$this->core->logger->warn('isUploaded: ' . implode('\\n', $this->objUpload->getMessages()));
throw new Exception('File is not uploaded!');
}
/**
* check if upload is valid
*/
// if (!$this->objUpload->isValid(self::UPLOAD_FIELD)) {
// $this->core->logger->warn('isValid: '.implode('\n', $this->objUpload->getMessages()));
// throw new Exception('Uploaded file is not valid!');
// }
if ($this->getRequest()->isPost()) {
$objRequest = $this->getRequest();
$this->intParentId = $objRequest->getParam('folderId');
/**
* check if is image or else document
*/
if ($this->intParentId > 0 && $this->intParentId != '') {
if (strpos($this->objUpload->getMimeType(self::UPLOAD_FIELD), 'image/') !== false) {
$this->handleImageUpload();
} else {
$this->handleFileUpload();
}
}
}
} catch (Exception $exc) {
$this->core->logger->err($exc);
}
}
示例12: upload
/**
* 上传图片处理方法,
* 还有中文bug
*/
public function upload($fileDir, $imgpath)
{
$adapter = new Zend_File_Transfer_Adapter_Http();
// 不需要渲染模板页
$this->getFrontController()->setParam('noViewRenderer', true);
// 你存放上传文件的文件夹
$adapter->setDestination($fileDir);
$adapter->addValidator('Extension', false, 'gif,jpeg,png,jpg');
//设置上传文件的后缀名
$adapter->addValidator('Count', false, array('min' => 1, 'max' => 5));
//设置上传文件的个数
$adapter->addValidator('ImageSize', false, array('minwidth' => 0, 'maxwidth' => 40960, 'minhight' => 0, 'maxhight' => 40960));
////设置上传图片的大小
$adapter->addValidator('FilesSize', false, array('min' => '4KB', 'max' => '4096KB'));
////设置上传文件的大小
//添加过滤器来修改上传文件的名称
if ($imgpath) {
$adapter->addFilter('Rename', array('target' => $imgpath, 'overwrite' => true));
}
/* $fileInfo = $this->adapter->getFileInfo();
foreach ($fileInfo as $file=>$info) { //file-文件名
if ($this->adapter->isValid($file)) {
var_dump($info);die;
}
} */
// 返回上传后出现在信息
if (!$adapter->receive()) {
/* $messages = $adapter->getMessages ();
echo implode ( "n", $messages ); */
$out[Response::ERRNO] = 0;
$out[Response::MSG] = '上传成功!';
Response::out($out);
exit;
} else {
$out[Response::ERRNO] = 1;
$out[Response::MSG] = '上传失败!';
Response::out($out);
exit;
}
}
示例13: uploadAction
public function uploadAction()
{
$this->_helper->layout->disableLayout();
if ($this->getRequest()->isPost()) {
$cnt = 0;
$mapper = new Application_Model_UploadMapper();
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Size', false, 20000, 'file2');
$upload->setDestination('uploads/');
$files = $upload->getFileInfo();
foreach ($files as $file => $info) {
//$transform = new Zend_Image_Transform( $image );
$ext = end(explode(".", $info['name']));
$uuid = uniqid();
$upload->addFilter('Rename', array('target' => 'uploads/' . $uuid . '.' . $ext, 'overwrite' => true));
if ($upload->isValid($file)) {
$upload->receive($file);
}
$imageSize[0] = 150;
$imageSize[1] = 150;
$imageSize = getimagesize('uploads/' . $uuid . '.' . $ext);
$name = $info['name'];
$type = $info['type'];
$size = $info['size'];
$file = 'uploads/' . $name;
$_post['file'] = $file;
$_post['name'] = $name;
$_post['type'] = $type;
$_post['size'] = $size;
$_post['uuid'] = $uuid;
$_post['width'] = $imageSize[0];
$_post['height'] = $imageSize[1];
$_post['ext'] = $ext;
$htmldata[$cnt] = $_post;
$mapper->saveall($htmldata[$cnt]);
$cnt++;
}
$data = json_encode($htmldata);
echo $data;
}
}
示例14: upload
private function upload()
{
$todir = $this->_cfg['temp']['path'] . $this->getRequest()->getParam('docid', 'unknown_doc');
if (!file_exists($todir)) {
mkdir($todir);
}
$adapter = new Zend_File_Transfer_Adapter_Http(array('ignoreNoFile' => true));
$filename = $adapter->getFileName('upload', false);
$adapter->addValidator('Extension', false, $this->getRequest()->getParam('type') == 'images' ? $this->imgExts : $this->fileExts)->addValidators($this->getRequest()->getParam('type') == 'images' ? $this->imgValidators : $this->fileValidators)->addFilter('Rename', array('target' => $todir . DIRECTORY_SEPARATOR . iconv('utf-8', FS_CHARSET, $filename), 'overwrite' => true));
// $adapter->setDestination($todir);
$result = new stdClass();
$result->messages = array();
$result->uploadedUrl = '';
if (!$adapter->isValid()) {
$result->messages = $adapter->getMessages();
} else {
if ($adapter->receive() && $adapter->isUploaded()) {
$result->uploadedUrl = ($this->getRequest()->getParam('type') == 'images' ? '' : 'downloads/') . $filename;
}
}
$result->CKEditorFuncNum = $this->getRequest()->getParam('CKEditorFuncNum');
return $result;
}
示例15: uploadFiles
/**
*
* @return array
*/
public function uploadFiles()
{
$return = array('files' => array());
try {
$dir = $this->getDirDocs();
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($dir);
$typeValidator = new Zend_Validate_File_Extension($this->_extensions);
$sizeFile = new Zend_Validate_File_Size($this->_maxSize);
$adapter->addValidator($typeValidator, true)->addValidator($sizeFile, true);
$files = $adapter->getFileInfo();
foreach ($files as $file => $info) {
if (!$adapter->isUploaded($file)) {
continue;
}
$name = $this->_getNewFileName($dir, $info['name']);
$fileInfo = array('size' => $info['size'], 'name' => $name);
if (!$adapter->isValid($file)) {
$messages = $adapter->getMessages();
$fileInfo['error'] = array_shift($messages);
$return['files'][] = $fileInfo;
continue;
}
$adapter->addFilter('Rename', $dir . $name, $file);
$adapter->receive($file);
$pathFile = $this->publicFileUrl($dir . $name);
$fileInfo['url'] = $pathFile;
$fileInfo['delete_url'] = '/client/document/delete/?file=' . $pathFile;
$fileInfo['delete_type'] = 'DELETE';
$return['files'][] = $fileInfo;
}
return $return;
} catch (Exception $e) {
return $return;
}
}