本文整理汇总了PHP中Zend_File_Transfer_Adapter_Http::setValidators方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_File_Transfer_Adapter_Http::setValidators方法的具体用法?PHP Zend_File_Transfer_Adapter_Http::setValidators怎么用?PHP Zend_File_Transfer_Adapter_Http::setValidators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_File_Transfer_Adapter_Http
的用法示例。
在下文中一共展示了Zend_File_Transfer_Adapter_Http::setValidators方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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));
}
}
示例3: upload
/**
* Upload plugin zip file.
*
* @param string $formName name of the form on the user interface
* @param stdclass $json
* @return array
*
* $tempFileName,
* $tempFilePath,
* $json
*/
function upload($formName, $json)
{
$rootPath = RM_Environment::getConnector()->getRootPath();
//1. upload zip - check if this file name a .zip extension
//2. move zip to temp directory
$tempFolderName = 'temp';
$tempFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . $tempFolderName;
$validators = array();
$validators[] = new Zend_Validate_File_Extension('zip');
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setValidators($validators);
try {
$adapter->setDestination($tempFolderPath);
} catch (Zend_File_Transfer_Exception $exception) {
throw new RM_Exception($exception->getMessage());
}
if (!$adapter->receive()) {
$message = $this->_translate->_('Admin.Plugins.InstallMsg', 'UploadFailed');
$message .= '. ' . implode("; ", $adapter->getMessages());
throw new RM_Exception($message);
} else {
$json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'UploadSuccess'));
}
//3. create new directory for a plugin
$files = $adapter->getFileInfo();
$tempFileName = $files[$formName]['name'];
$tempFilePath = $tempFolderPath . DIRECTORY_SEPARATOR . $tempFileName;
return array($tempFileName, $tempFilePath, $json);
}
示例4: _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;
}
示例5: upload
/**
* Metdo responsavel por persistir os uploads
* @param type $destino
* @param type $thumb
* @param type $validFile
* @param type $invalidFile
* @return type
*/
public static function upload($destino = 'anexoArtefato', $thumb = FALSE, $validFile = TRUE, $invalidFile = TRUE, $validImageSize = TRUE)
{
$configs = \Core_Registry::get('configs');
$upload = new \Zend_File_Transfer_Adapter_Http();
$files = $upload->getFileInfo();
$filesUp = array();
$return = array();
$error = false;
$pasta = 'anexo-material';
if ($destino == 'anexoArtefato') {
$pasta = 'anexo-artefato';
}
$path = current(explode('application', __DIR__)) . 'data' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $pasta . DIRECTORY_SEPARATOR;
foreach ($files as $file => $info) {
$upload = new \Zend_File_Transfer_Adapter_Http();
$upload->setDestination($path);
$upload->setValidators(array());
$upload->addValidator('Size', TRUE, array('max' => '100MB', 'messages' => "O tamanho do arquivo é superior ao permitido. O tamanho permitido é 100MB."));
self::_invalidFile($invalidFile, $upload);
self::_validFile($validFile, $upload);
self::_validImageSize($validImageSize, $upload);
self::_getValidator($upload);
if ($upload->isValid($file)) {
$fileinfo = pathinfo($info['name']);
$upload->receive($file);
$filesUp[] = $upload->getFileName($file);
$return[] = array('name' => $upload->getFileName($file), 'size' => $upload->getFileSize($file));
} else {
$error = $upload->getMessages();
break;
}
}
if ($error) {
if (count($filesUp)) {
foreach ($filesUp as $file) {
unlink($file);
}
}
return array('errors' => $error);
}
if ($thumb) {
$pasta = current(explode('application', __DIR__)) . 'data' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR;
foreach ($filesUp as $endereco) {
$fileinfo = pathinfo($endereco);
$image = \WideImage::load($endereco);
$image->resize(300, 300, 'outside')->crop('50% - 150', '50% - 150', 300, 300)->saveToFile($pasta . $fileinfo['filename'] . '_300_X_300.' . strtolower($fileinfo['extension']));
$image->resize(133, 89, 'outside')->crop('50% - 67', '50% - 45', 133, 89)->saveToFile($pasta . $fileinfo['filename'] . '_133_X_89.' . strtolower($fileinfo['extension']));
}
}
return $return;
}