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


PHP Zend_Validate_File_MimeType::isValid方法代码示例

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


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

示例1: testBasic

 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array('image/gif', true), array('image', true), array('test/notype', false), array('image/gif, image/jpeg', true), array(array('image/vasa', 'image/gif'), true), array(array('image/jpeg', 'gif'), true), array(array('image/jpeg', 'jpeg'), false));
     $files = array('name' => 'testsize.mo', 'type' => 'image/gif', 'size' => 200, 'tmp_name' => dirname(__FILE__) . '/_files/testsize.mo', 'error' => 0);
     foreach ($valuesExpected as $element) {
         $validator = new Zend_Validate_File_MimeType($element[0]);
         $this->assertEquals($element[1], $validator->isValid(dirname(__FILE__) . '/_files/testsize.mo', $files));
     }
 }
开发者ID:lortnus,项目名称:zf1,代码行数:14,代码来源:MimeTypeTest.php

示例2: 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);
 }
开发者ID:bokultis,项目名称:kardiomedika,代码行数:20,代码来源:MimeType.php

示例3: testBasic

 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array(array('image/jpg', 'image/jpeg'), true), array('image', true), array('test/notype', false), array('image/gif, image/jpg, image/jpeg', true), array(array('image/vasa', 'image/jpg', 'image/jpeg'), true), array(array('image/jpg', 'image/jpeg', 'gif'), true), array(array('image/gif', 'gif'), false), array('image/jp', false), array('image/jpg2000', false), array('image/jpeg2000', false));
     $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));
     }
 }
开发者ID:vicfryzel,项目名称:zf,代码行数:18,代码来源:MimeTypeTest.php

示例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;
     }
 }
开发者ID:emitkowski,项目名称:magento-1.13.0.2,代码行数:19,代码来源:Uploader.php

示例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;
}
开发者ID:svenjantzen,项目名称:imscp,代码行数:16,代码来源:Input.php

示例6: 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));
     }
 }
开发者ID:ThorstenSuckow,项目名称:conjoon,代码行数:25,代码来源:MimeTypeTest.php

示例7: 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)
 {
     $this->_loadParams();
     $mimetypes = $this->_fields[$this->_fieldId]['params']['mimetypes'];
     if (is_array($mimetypes) && count($mimetypes)) {
         foreach ($mimetypes as $mime) {
             $this->addMimeType($mime);
         }
     }
     if ($file === null) {
         $file = array('type' => null, 'name' => $value);
     }
     if (isset($this->_dir)) {
         $value = $this->_dir . "/" . $value;
     }
     return parent::isValid($value, $file);
 }
开发者ID:bokultis,项目名称:kardiomedika,代码行数:27,代码来源:GenericMimeType.php

示例8: 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;
 }
开发者ID:bokultis,项目名称:kardiomedika,代码行数:55,代码来源:FileServer.php


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