本文整理汇总了PHP中Zend_Validate_File_MimeType类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_File_MimeType类的具体用法?PHP Zend_Validate_File_MimeType怎么用?PHP Zend_Validate_File_MimeType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Validate_File_MimeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderizaCamposRPS
/**
* Renderiza os campos para importação de RPS
*
* @return Contribuinte_Form_ImportacaoArquivo
*/
public function renderizaCamposRPS()
{
// Validador do xml
$oValidaXml = new Zend_Validate_File_MimeType(array('application/xml'));
$oValidaXml->setMessages(array(Zend_Validate_File_MimeType::FALSE_TYPE => 'O arquivo "%value%" não possui o formato "XML".', Zend_Validate_File_MimeType::NOT_DETECTED => 'O arquivo "%value%" é inválido ou está corrompido.'));
$oElm = $this->createElement('file', 'arquivo');
$oElm->setLabel('Arquivo XML: ');
$oElm->setAttrib('class', 'input');
$oElm->setAttrib('accept', '*/*');
// Android
$oElm->addValidator($oValidaXml);
$oElm->setRequired(TRUE);
$this->addElement($oElm);
return $this;
}
示例2: getMimeType
/**
* @param $value
* @param null $file
* @return bool
*/
public function getMimeType($value, $file = null)
{
if ($file === null) {
$file = array('type' => null, 'name' => $value);
}
// Is file readable ?
//$1 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_READABLE);
}
$validate = new Zend_Validate_File_MimeType('');
$mimefile = $validate->getMagicFile();
if (class_exists('finfo', false)) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
if (!empty($mimefile) && empty($finfo)) {
$finfo = @finfo_open($const, $mimefile);
}
if (empty($finfo)) {
$finfo = @finfo_open($const);
}
$type = null;
if (!empty($finfo)) {
$type = finfo_file($finfo, $value);
}
}
if (empty($type) && (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))) {
$type = mime_content_type($value);
}
if (empty($type) && $this->_headerCheck) {
$type = $file['type'];
}
if (empty($type)) {
return $this->_throw($file, self::NOT_DETECTED);
}
return $type;
}
示例3: testAddMimeType
/**
* Ensures that addMimeType() returns expected value
*
* @return void
*/
public function testAddMimeType()
{
$validator = new Zend_Validate_File_MimeType('image/gif');
$validator->addMimeType('text');
$this->assertEquals('image/gif,text', $validator->getMimeType());
$this->assertEquals(array('image/gif', 'text'), $validator->getMimeType(true));
$validator->addMimeType('jpg, to');
$this->assertEquals('image/gif,text,jpg,to', $validator->getMimeType());
$this->assertEquals(array('image/gif', 'text', 'jpg', 'to'), $validator->getMimeType(true));
$validator->addMimeType(array('zip', 'ti'));
$this->assertEquals('image/gif,text,jpg,to,zip,ti', $validator->getMimeType());
$this->assertEquals(array('image/gif', 'text', 'jpg', 'to', 'zip', 'ti'), $validator->getMimeType(true));
$validator->addMimeType('');
$this->assertEquals('image/gif,text,jpg,to,zip,ti', $validator->getMimeType());
$this->assertEquals(array('image/gif', 'text', 'jpg', 'to', 'zip', 'ti'), $validator->getMimeType(true));
}
示例4: checkMimeType
/**
* Used to check if uploaded file mime type is valid or not
*
* @param array $validTypes
* @access public
* @return bool
*/
public function checkMimeType($validTypes = array())
{
try {
if (count($validTypes) > 0) {
$validator = new Zend_Validate_File_MimeType($validTypes);
return $validator->isValid($this->_file['tmp_name']);
}
return true;
} catch (Exception $e) {
return false;
}
}
示例5: checkMimeType
/**
* Checks if a file match the given mimetype(s)
*
* @param string $pathFile File to check for mimetype
* @param array|string $mimeTypes Accepted mimetype(s)
* @return bool TRUE if the file match the givem mimetype(s), FALSE otherwise
*/
function checkMimeType($pathFile, array $mimeTypes)
{
$mimeTypes['headerCheck'] = true;
$validator = new Zend_Validate_File_MimeType($mimeTypes);
if ($validator->isValid($pathFile)) {
return true;
}
return false;
}
示例6: testDualValidation
/**
* @group ZF-9686
*/
public function testDualValidation()
{
$valuesExpected = array(array('image', true));
$filetest = dirname(__FILE__) . '/_files/picture.jpg';
$files = array('name' => 'picture.jpg', 'type' => 'image/jpg', 'size' => 200, 'tmp_name' => $filetest, 'error' => 0);
foreach ($valuesExpected as $element) {
$options = array_shift($element);
$expected = array_shift($element);
$validator = new Zend_Validate_File_MimeType($options);
$validator->enableHeaderCheck();
$this->assertEquals($expected, $validator->isValid($filetest, $files), "Test expected " . var_export($expected, 1) . " with " . var_export($options, 1) . "\nMessages: " . var_export($validator->getMessages(), 1));
$validator = new Zend_Validate_File_MimeType($options);
$validator->enableHeaderCheck();
$this->assertEquals($expected, $validator->isValid($filetest, $files), "Test expected " . var_export($expected, 1) . " with " . var_export($options, 1) . "\nMessages: " . var_export($validator->getMessages(), 1));
}
}
示例7: testDisablingTryCommonMagicFilesIgnoresCommonLocations
/**
* @group ZF-11784
*/
public function testDisablingTryCommonMagicFilesIgnoresCommonLocations()
{
$filetest = dirname(__FILE__) . '/_files/picture.jpg';
$files = array('name' => 'picture.jpg', 'size' => 200, 'tmp_name' => $filetest, 'error' => 0);
$validator = new Zend_Validate_File_MimeType(array('image/jpeg', 'image/jpeg; charset=binary'));
$goodEnvironment = $validator->isValid($filetest, $files);
if ($goodEnvironment) {
/**
* The tester's environment has magic files that are properly read by PHP
* This prevents the test from being relevant in the environment
*/
$this->markTestSkipped('This test environment works as expected with the common magic files, preventing this from being testable.');
} else {
// The common magic files detected the image as application/octet-stream -- try the PHP default
// Note that if this branch of code is entered then testBasic, testDualValidation,
// as well as Zend_Validate_File_IsCompressedTest::testBasic and Zend_Validate_File_IsImageTest::testBasic
// will be failing as well.
$validator = new Zend_Validate_File_MimeType(array('image/jpeg', 'image/jpeg; charset=binary'));
$validator->setTryCommonMagicFilesFlag(false);
$this->assertTrue($validator->isValid($filetest, $files));
}
}
示例8: 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'));
}
示例9: init
/**
* Metodo para inicializacao do Formulario
* @see Zend_Form::init()
*/
public function init()
{
$aValidatores = array(new Zend_Validate_Float(array('locale' => 'br')), new Zend_Validate_LessThan(100), new Zend_Validate_GreaterThan(-1.0E-7));
$this->setEnctype("multipart/form-data");
$this->setMethod(Zend_Form::METHOD_POST);
$oElm = $this->createElement('hidden', 'im');
$oElm->setRequired(TRUE);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'nome_contribuinte');
$oElm->setLabel('Contribuinte:');
$oElm->setAttrib('class', 'span6');
$oElm->setAttrib('readonly', TRUE);
$oElm->setRequired(TRUE);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'avisofim_emissao_nota');
$oElm->setAttrib('class', 'span1 mask-numero');
$oElm->setAttrib('maxlength', 3);
$oElm->setLabel('Quantidade para aviso:');
$oElm->setRequired(TRUE);
$this->addElement($oElm);
$oElm = $this->createElement('hidden', 'max_deducao', array('append' => '%', 'description' => '"0" para desabilitar dedução'));
$oElm->setLabel('Limite para dedução: ');
$oElm->setAttrib('class', 'span1 mask-porcentagem');
$oElm->setValidators($aValidatores);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'pis', array('append' => '%'));
$oElm->setLabel('PIS: ');
$oElm->setAttrib('class', 'span1 mask-porcentagem');
$oElm->setValidators($aValidatores);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'cofins', array('append' => '%'));
$oElm->setLabel('COFINS: ');
$oElm->setAttrib('class', 'span1 mask-porcentagem');
$oElm->setValidators($aValidatores);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'inss', array('append' => '%'));
$oElm->setLabel('INSS: ');
$oElm->setAttrib('class', 'span1 mask-porcentagem');
$oElm->setValidators($aValidatores);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'ir', array('append' => '%'));
$oElm->setLabel('IR: ');
$oElm->setAttrib('class', 'span1 mask-porcentagem');
$oElm->setValidators($aValidatores);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'csll', array('append' => '%'));
$oElm->setLabel('CSLL: ');
$oElm->setAttrib('class', 'span1 mask-porcentagem');
$oElm->setValidators($aValidatores);
$this->addElement($oElm);
$oElm = $this->createElement('text', 'valor_iss_fixo', array('append' => '%'));
$oElm->setLabel('Aliquota ISS Fixa:');
$oElm->setAttrib('class', 'span1 mask-porcentagem');
$oElm->setValidators($aValidatores);
$this->addElement($oElm);
// Validador do file-input
$oValidaJPG = new Zend_Validate_File_MimeType(array('image/jpeg'));
$oValidaJPG->setMessages(array(Zend_Validate_File_MimeType::FALSE_TYPE => 'O arquivo "%value%" não possui o formato "JPG".', Zend_Validate_File_MimeType::NOT_DETECTED => 'O arquivo "%value%" é inválido ou está corrompido.'));
$oElm = $this->createElement('file', 'imagem_logo');
$oElm->setLabel('Imagem de Logo: ');
$oElm->setAttrib('class', 'input');
$oElm->setAttrib('accept', '*/*');
$oElm->addValidator($oValidaJPG);
$this->addElement($oElm);
$this->addElement('submit', 'submit', array('label' => 'Salvar', 'buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_SUCCESS));
return $this;
}
示例10: unzip
/**
* Unzip file
*
* @param string $path
* @return boolean
*/
public function unzip($path, $newDir = false)
{
$filePath = $this->getRealPath($path);
if (!file_exists($filePath)) {
$this->returnError('File does not exists ' . $path);
return false;
}
// get the absolute path to $file
$dir = pathinfo($filePath, PATHINFO_DIRNAME);
$packageName = pathinfo($filePath, PATHINFO_FILENAME);
if ($newDir) {
$dir .= DIRECTORY_SEPARATOR . $packageName;
}
$zip = new ZipArchive();
$res = $zip->open($filePath);
if (!$res) {
$this->returnError('Cannot extract file');
return false;
}
$tmpDir = APPLICATION_PATH . '/../tmp/' . session_id() . '-' . $packageName;
$zip->extractTo($tmpDir);
$zip->close();
//check size
$extractSize = $this->_helper->getDirSize($tmpDir);
if ($extractSize > $this->_helper->getFreeSpace()) {
$this->_rrmdir($tmpDir);
$this->returnError('Not enough space on disk');
return false;
}
$files = array();
$this->_rlistFiles($tmpDir, $files);
$mimeValidator = new Zend_Validate_File_MimeType($this->_helper->getDefaultMimeTypes());
$extValidator = new Zend_Validate_File_Extension($this->_helper->getDefaultExtensions());
foreach ($files as $currFile) {
if (!$extValidator->isValid($currFile)) {
$this->_rrmdir($tmpDir);
$this->returnError(sprintf('File [%s] has invalid extension.', basename($currFile)));
return false;
}
if (!$mimeValidator->isValid($currFile)) {
$this->_rrmdir($tmpDir);
$this->returnError(sprintf('File [%s] has invalid mime type.', basename($currFile)));
return false;
}
}
$this->_rcopy($tmpDir, $dir);
$this->_rrmdir($tmpDir);
return true;
}
示例11: testOptionsAtConstructor
public function testOptionsAtConstructor()
{
$validator = new Zend_Validate_File_MimeType(array('image/gif', 'image/jpg', 'headerCheck' => true));
$this->assertTrue($validator->getHeaderCheck());
$this->assertEquals('image/gif,image/jpg', $validator->getMimeType());
}
示例12: __construct
/**
* Sets validator options
*
* @param string|array|Zend_Config $compression
* @return void
*/
public function __construct($mimetype = array())
{
if ($mimetype instanceof Zend_Config) {
$mimetype = $mimetype->toArray();
}
$temp = array();
// http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
$default = array('application/arj', 'application/gnutar', 'application/lha', 'application/lzx', 'application/vnd.ms-cab-compressed', 'application/x-ace-compressed', 'application/x-arc', 'application/x-archive', 'application/x-arj', 'application/x-bzip', 'application/x-bzip2', 'application/x-cab-compressed', 'application/x-compress', 'application/x-compressed', 'application/x-cpio', 'application/x-debian-package', 'application/x-eet', 'application/x-gzip', 'application/x-java-pack200', 'application/x-lha', 'application/x-lharc', 'application/x-lzh', 'application/x-lzma', 'application/x-lzx', 'application/x-rar', 'application/x-sit', 'application/x-stuffit', 'application/x-tar', 'application/zip', 'application/zoo', 'multipart/x-gzip');
if (is_array($mimetype)) {
$temp = $mimetype;
if (array_key_exists('magicfile', $temp)) {
unset($temp['magicfile']);
}
if (array_key_exists('headerCheck', $temp)) {
unset($temp['headerCheck']);
}
if (empty($temp)) {
$mimetype += $default;
}
}
if (empty($mimetype)) {
$mimetype = $default;
}
parent::__construct($mimetype);
}
示例13: __construct
/**
* Sets validator options
*
* @param string|array|Zend_Config $mimetype
* @return void
*/
public function __construct($mimetype = array())
{
if ($mimetype instanceof Zend_Config) {
$mimetype = $mimetype->toArray();
}
$temp = array();
// http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
// http://www.iana.org/assignments/media-types/image/
$default = array('application/cdf', 'application/dicom', 'application/fractals', 'application/postscript', 'application/vnd.hp-hpgl', 'application/vnd.oasis.opendocument.graphics', 'application/x-cdf', 'application/x-cmu-raster', 'application/x-ima', 'application/x-inventor', 'application/x-koan', 'application/x-portable-anymap', 'application/x-world-x-3dmf', 'image/bmp', 'image/c', 'image/cgm', 'image/fif', 'image/gif', 'image/jpeg', 'image/jpm', 'image/jpx', 'image/jp2', 'image/naplps', 'image/pjpeg', 'image/png', 'image/svg', 'image/svg+xml', 'image/tiff', 'image/vnd.adobe.photoshop', 'image/vnd.djvu', 'image/vnd.fpx', 'image/vnd.net-fpx', 'image/x-cmu-raster', 'image/x-cmx', 'image/x-coreldraw', 'image/x-cpi', 'image/x-emf', 'image/x-ico', 'image/x-icon', 'image/x-jg', 'image/x-ms-bmp', 'image/x-niff', 'image/x-pict', 'image/x-pcx', 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-greymap', 'image/x-portable-pixmap', 'image/x-quicktime', 'image/x-rgb', 'image/x-tiff', 'image/x-unknown', 'image/x-windows-bmp', 'image/x-xpmi');
if (is_array($mimetype)) {
$temp = $mimetype;
if (array_key_exists('magicfile', $temp)) {
unset($temp['magicfile']);
}
if (array_key_exists('headerCheck', $temp)) {
unset($temp['headerCheck']);
}
if (empty($temp)) {
$mimetype += $default;
}
}
if (empty($mimetype)) {
$mimetype = $default;
}
parent::__construct($mimetype);
}
示例14: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the imagesize of $value is at least min and
* not bigger than max
*
* @param string $value Real file to check for image size
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
if ($file === null) {
$file = array('type' => null, 'name' => $value);
}
if (isset($this->_dir)) {
$value = $this->_dir . "/" . $value;
}
return parent::isValid($value, $file);
}
示例15: __construct
/**
* Sets validator options
*
* @param string|array|Zend_Config $compression
* @return void
*/
public function __construct($mimetype = array())
{
if ($mimetype instanceof Zend_Config) {
$mimetype = $mimetype->toArray();
}
$temp = array();
$default = array('application/x-tar', 'application/x-cpio', 'application/x-debian-package', 'application/x-archive', 'application/x-arc', 'application/x-arj', 'application/x-lharc', 'application/x-lha', 'application/x-rar', 'application/zip', 'application/zoo', 'application/x-eet', 'application/x-java-pack200', 'application/x-compress', 'application/x-gzip', 'application/x-bzip2');
if (is_array($mimetype)) {
$temp = $mimetype;
if (array_key_exists('magicfile', $temp)) {
unset($temp['magicfile']);
}
if (array_key_exists('headerCheck', $temp)) {
unset($temp['headerCheck']);
}
if (empty($temp)) {
$mimetype += $default;
}
}
if (empty($mimetype)) {
$mimetype = $default;
}
parent::__construct($mimetype);
}