当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_File_Transfer_Adapter_Http::getValidator方法代码示例

本文整理汇总了PHP中Zend_File_Transfer_Adapter_Http::getValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_File_Transfer_Adapter_Http::getValidator方法的具体用法?PHP Zend_File_Transfer_Adapter_Http::getValidator怎么用?PHP Zend_File_Transfer_Adapter_Http::getValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_File_Transfer_Adapter_Http的用法示例。


在下文中一共展示了Zend_File_Transfer_Adapter_Http::getValidator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: uploadAction

 public function uploadAction()
 {
     if (!empty($_FILES)) {
         try {
             $path = '/var/apps/iphone/certificates/';
             $base_path = Core_Model_Directory::getBasePathTo($path);
             $filename = uniqid() . '.pem';
             $app_id = $this->getRequest()->getParam('app_id');
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0775, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             $adapter->setValidators(array('Extension' => array('pem', 'case' => false)));
             $adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, \\'%s\\' only", '%extension%')));
             $files = $adapter->getFileInfo();
             foreach ($files as $file => $info) {
                 if (!$adapter->isUploaded($file)) {
                     throw new Exception($this->_('An error occurred during process. Please try again later.'));
                 } else {
                     if (!$adapter->isValid($file)) {
                         if (count($adapter->getMessages()) == 1) {
                             $erreur_message = $this->_('Error : <br/>');
                         } else {
                             $erreur_message = $this->_('Errors : <br/>');
                         }
                         foreach ($adapter->getMessages() as $message) {
                             $erreur_message .= '- ' . $message . '<br/>';
                         }
                         throw new Exception($erreur_message);
                     } else {
                         $adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $base_path . $filename, 'overwrite' => true)));
                         $adapter->receive($file);
                     }
                 }
             }
             $certificat = new Push_Model_Certificate();
             $certificat->find(array('type' => 'ios', 'app_id' => $app_id));
             if (!$certificat->getId()) {
                 $certificat->setType('ios')->setAppId($app_id);
             }
             $certificat->setPath($path . $filename)->save();
             $datas = array('success' => 1, 'files' => 'eeeee', 'message_success' => $this->_('Info successfully saved'), 'message_button' => 0, 'message_timeout' => 2);
         } catch (Exception $e) {
             $datas = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($datas));
     }
 }
开发者ID:bklein01,项目名称:siberian_cms_2,代码行数:49,代码来源:BackofficeController.php

示例2: upload

 public function upload($params = array())
 {
     if (!is_dir($params['destination_folder'])) {
         mkdir($params['destination_folder'], 0777, true);
     }
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($params['destination_folder']);
     $adapter->setValidators($params['validators']);
     if ($adapter->getValidator('ImageSize')) {
         $adapter->getValidator('ImageSize')->setMessages(array('fileImageSizeWidthTooBig' => $this->_('Image too large, %spx maximum allowed.', '%maxwidth%'), 'fileImageSizeWidthTooSmall' => $this->_('Image not large enough, %spx minimum allowed.', '%minwidth%'), 'fileImageSizeHeightTooBig' => $this->_('Image too high, %spx maximum allowed.', '%maxheight%'), 'fileImageSizeHeightTooSmall' => $this->_('Image not high enough, %spx minimum allowed.', '%minheight%'), 'fileImageSizeNotDetected' => $this->_("The image size '%s' could not be detected.", '%value%'), 'fileImageSizeNotReadable' => $this->_("The image '%s' does not exist", '%value%')));
     }
     if ($adapter->getValidator('Size')) {
         $adapter->getValidator('Size')->setMessages(array('fileSizeTooBig' => $this->_("Image too large, '%s' allowed.", '%max%'), 'fileSizeTooSmall' => $this->_("Image not large enough, '%s' allowed.", '%min%'), 'fileSizeNotFound' => $this->_("The image '%s' does not exist", '%value%')));
     }
     if ($adapter->getValidator('Extension')) {
         $adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, '%s' only", '%extension%'), 'fileExtensionNotFound' => $this->_("The file '%s' does not exist", '%value%')));
     }
     $files = $adapter->getFileInfo();
     $return_file = '';
     foreach ($files as $file => $info) {
         //Créé l'image sur le serveur
         if (!$adapter->isUploaded($file)) {
             throw new Exception($this->_('An error occurred during process. Please try again later.'));
         } else {
             if (!$adapter->isValid($file)) {
                 if (count($adapter->getMessages()) == 1) {
                     $erreur_message = $this->_('Error : <br/>');
                 } else {
                     $erreur_message = $this->_('Errors : <br/>');
                 }
                 foreach ($adapter->getMessages() as $message) {
                     $erreur_message .= '- ' . $message . '<br/>';
                 }
                 throw new Exception($erreur_message);
             } else {
                 $new_name = uniqid("file_");
                 if (isset($params['uniq']) and $params['uniq'] == 1) {
                     if (isset($params['desired_name'])) {
                         $new_name = $params['desired_name'];
                     } else {
                         $format = pathinfo($info["name"], PATHINFO_EXTENSION);
                         if (!in_array($format, array("png", "jpg", "jpeg", "gif"))) {
                             $format = "jpg";
                         }
                         $new_name = $params['uniq_prefix'] . uniqid() . ".{$format}";
                     }
                     $new_pathname = $params['destination_folder'] . '/' . $new_name;
                     $adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $new_pathname, 'overwrite' => true)));
                 }
                 $adapter->receive($file);
                 $return_file = $new_name;
             }
         }
     }
     return $return_file;
 }
开发者ID:bklein01,项目名称:siberian_cms_2,代码行数:56,代码来源:Uploader.php

示例3: handleUpload

 public function handleUpload($collection)
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     if ($request->getHeader("Content-Length") == 0) {
         $response->setHttpResponseCode(204)->sendResponse();
         exit;
     }
     $mimeType = Bbx_Model::load($collection->getModelName())->getMimeType();
     $max_size = ini_get('upload_max_filesize');
     $post_max = ini_get('post_max_size');
     if ($post_max < $max_size) {
         $max_size = $post_max;
     }
     $upload = new Zend_File_Transfer_Adapter_Http();
     // TODO throws error 'Magicfile can not be set. There is no finfo extension installed' (Zend_Validate_File_MimeType 193)
     //		$upload->addValidator('MimeType', false, $mimeType);
     $upload->getValidator('Zend_Validate_File_Upload')->setMessage('File is too large - max size ' . $max_size, Zend_Validate_File_Upload::INI_SIZE);
     if ($upload->receive()) {
         Bbx_Log::debug("upload received");
         $files = $upload->getFileInfo();
         $media = $files['file_data'];
         Bbx_Log::debug(print_r($media, true));
         $new_model = $collection->create();
         try {
             $new_model->attachMedia($media['tmp_name']);
             $new_model->save();
         } catch (Exception $e) {
             $new_model->delete();
             throw $e;
         }
         return $new_model;
     } else {
         $this->_throwUploadException($upload);
     }
 }
开发者ID:rdallasgray,项目名称:bbx,代码行数:36,代码来源:Media.php

示例4: dodajgaleriaAction

 public function dodajgaleriaAction($filefield)
 {
     $upload = new Zend_File_Transfer_Adapter_Http();
     $fileinfo = $upload->getFileInfo();
     $oRequest = $this->getRequest();
     if (!$oRequest->getParam('pro_id')) {
         $this->_redirect('adminn/produkty');
     }
     //walidacja pola zdjecie
     $oMimeValidator = new Zend_Validate_File_MimeType('image/jpg, image/jpeg');
     $oMimeValidator->setMessage('Zły format pliku.');
     $oUpload = new Zend_File_Transfer_Adapter_Http();
     $oUpload->addValidator($oMimeValidator);
     $oUpload->getValidator('Upload')->setMessage('Plik jest wymagany.', Zend_Validate_File_Upload::NO_FILE);
     try {
         $oConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/wizytowki.ini', 'wizytowki');
         $sWizytowkiKatalog = $oConfig->wizytowki->katalog;
         $sWizytowkaNazwa = FileNameManager::getName($sWizytowkiKatalog, $oUpload->getFileName('zdjecie', false));
         $oUpload->addFilter('Rename', $sWizytowkiKatalog . $sWizytowkaNazwa);
         $oUpload->receive($fileinfo[$filefield]['zdjecie']);
         $oGaleria = new Galeria();
         $aDane = array('gal_plik' => $sWizytowkaNazwa, 'gal_pro_id' => $oRequest->getParam('pro_id'));
         $oGaleria->insert($aDane);
     } catch (Exception $oException) {
         if ($sWizytowkaNazwa && file_exists($sWizytowkiKatalog . $sWizytowkaNazwa)) {
             unlink($sWizytowkiKatalog . $sWizytowkaNazwa);
         }
         $oRequest->setParam('error_zdjecie', 'Bład podczas zapisu.');
         return $this->_forward('dodajzdjecia');
     }
     $this->_redirect('admin/galeria?pro_id=' . $oRequest->getParam('pro_id'));
 }
开发者ID:stasiu38,项目名称:cms,代码行数:32,代码来源:AdminController.php

示例5: _uploadSupportingDocument

 /**
  * To upload supporting document
  *
  * @param int $referenceNum, int $agentSchemeNum
  *
  * This method provides a convenient way of uploading the supporting document.
  *
  */
 private function _uploadSupportingDocument()
 {
     $upload = new Zend_File_Transfer_Adapter_Http();
     // Reword error messages in upload validator
     $uploadValidator = $upload->getValidator('Upload');
     $uploadValidator->setMessages(array('fileUploadErrorIniSize' => 'File exceeds the maximum allowed size', 'fileUploadErrorFormSize' => 'File exceeds the defined form size', 'fileUploadErrorPartial' => 'File was only partially uploaded', 'fileUploadErrorNoFile' => 'File was not uploaded', 'fileUploadErrorNoTmpDir' => 'No temporary directory was found for file', 'fileUploadErrorCantWrite' => 'File can\'t be written', 'fileUploadErrorExtension' => 'An error occurred while uploading the file', 'fileUploadErrorAttack' => 'File was illegally uploaded', 'fileUploadErrorFileNotFound' => 'File was not found', 'fileUploadErrorUnknown' => 'Unknown error while uploading file'));
     // Add extension validator
     $upload->addValidator('Extension', false, implode(',', $this->_supportingDocumentModel->getDocumentExtensions()));
     $arrFiles = $upload->getFileInfo();
     foreach ($arrFiles as $key => $value) {
         if ($value['name'] == "") {
             unset($arrFiles[$key]);
         }
     }
     $upload->setDestination($this->getPath());
     $arrSupportedDocs = array();
     foreach ($arrFiles as $file => $info) {
         if ($upload->isValid($file)) {
             foreach ($_POST as $postKey => $postVal) {
                 if (substr($postKey, 0, 9) == 'filename_') {
                     if ($postVal == $info['name']) {
                         $index = substr($postKey, 9);
                         $type = $_POST["description_{$index}"];
                     }
                 }
             }
             $upload->receive($file);
             $arrSupportedDocs[] = array('type' => $type, 'fullPath' => $this->getPath() . $info['name'], 'name' => $info['name'], 'size' => filesize($this->getPath() . $info['name']));
         } else {
             // Validation failed
             $arrSupportedDocs[] = array('id' => '', 'type' => 'badfile', 'fullPath' => '', 'name' => $info['name'], 'size' => '', 'error' => implode(', ', $upload->getMessages()));
         }
     }
     return $arrSupportedDocs;
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:43,代码来源:SupportingDocument.php

示例6: _upload

 /**
  * metod que realiza o upload e a persistencia do Arquivo
  */
 protected function _upload($dto)
 {
     $configs = \Core_Registry::get('configs');
     $upload = new \Zend_File_Transfer_Adapter_Http();
     $files = $upload->getFileInfo();
     $filesUp = array();
     $return = array();
     $error = false;
     foreach ($files as $file => $info) {
         $upload->setDestination($configs['upload']['material']);
         $upload->setValidators(array());
         $upload->addValidator('Size', TRUE, array('max' => $configs['upload']['materialApoioMaxSize'], 'messages' => "O tamanho do arquivo é superior ao permitido. O tamanho permitido é 25MB."));
         $upload->addValidator('ExcludeExtension', TRUE, array('dll', 'msi', 'phtml', 'phar', 'pyc', 'py', 'jar', 'bat', 'com', 'exe', 'pif', 'bin', 'sh', 'pl', 'php') + array('messages' => "Extensão do arquivo inválida."));
         $upload->getValidator('Upload')->setMessages(array('fileUploadErrorNoFile' => "Arquivo não selecionado."));
         if ($upload->isValid($file)) {
             $fileinfo = pathinfo($info['name']);
             $upload->receive($file);
             $filesUp[] = $upload->getFileName($file);
             $return[] = array('name' => $upload->getFileName($file));
         } else {
             $error = $upload->getMessages();
             break;
         }
     }
     if ($error) {
         if (count($filesUp)) {
             foreach ($filesUp as $file) {
                 unlink($file);
             }
         }
         return array('errors' => $error);
     }
     return $return;
 }
开发者ID:sgdoc,项目名称:sgdoce-codigo,代码行数:37,代码来源:Documento.php


注:本文中的Zend_File_Transfer_Adapter_Http::getValidator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。