當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validation::extension方法代碼示例

本文整理匯總了PHP中Validation::extension方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validation::extension方法的具體用法?PHP Validation::extension怎麽用?PHP Validation::extension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Validation的用法示例。


在下文中一共展示了Validation::extension方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: extension

 /**
  * Checks if extension is (not) one of given extensions
  *
  * @param string $check Extension to check (without leading dot)
  * @param mixed $deny True or * blocks any extension,
  * 	an array containing extensions (without a leading dot) selectively blocks,
  * 	false blocks no extension
  * @param mixed $allow True or * allows any extension,
  * 	an array containing extensions (without leading dot) selectively allows,
  * 	false allows no extension
  * @return boolean
  */
 function extension($check, $deny = false, $allow = true)
 {
     if (!is_string($check) || !preg_match('/^[\\w0-9]+(\\.[\\w0-9]+)?$/', $check)) {
         return false;
     }
     list($deny, $allow) = self::_normalize($deny, $allow);
     if ($deny === true || is_array($deny) && Validation::extension($check, $deny)) {
         return false;
     }
     if ($allow !== true && (is_array($allow) && !Validation::extension($check, $allow))) {
         return false;
     }
     return true;
 }
開發者ID:rcaravita,項目名稱:jodeljodel,代碼行數:26,代碼來源:media_validation.php

示例2: validateName

 function validateName($file = array(), $ext = array())
 {
     $err = array();
     $i = 0;
     foreach ($file as $file) {
         $i++;
         if (!empty($file['name'])) {
             if (!Validation::extension($file['name'], $ext)) {
                 return false;
             }
         }
     }
     return true;
 }
開發者ID:koprals,項目名稱:coda-gosales-hsbc,代碼行數:14,代碼來源:Setting.php

示例3: validFile

 function validFile($check, $settings)
 {
     $_default = array('required' => false, 'extensions' => array('jpg', 'jpeg', 'gif', 'png'));
     $_settings = array_merge($_default, ife(is_array($settings), $settings, array()));
     // Remove first level of Array
     $_check = array_shift($check);
     if ($_settings['required'] == false && $_check['size'] == 0) {
         return true;
     }
     // No file uploaded.
     if ($_settings['required'] && $_check['size'] == 0) {
         return false;
     }
     // Check for Basic PHP file errors.
     if ($_check['error'] !== 0) {
         return false;
     }
     // Use PHPs own file validation method.
     if (is_uploaded_file($_check['tmp_name']) == false) {
         return false;
     }
     // Valid extension
     return Validation::extension($_check, $_settings['extensions']);
 }
開發者ID:roae,項目名稱:hello-world,代碼行數:24,代碼來源:tiny_image.php

示例4: testExtension

 /**
  * testExtension method
  *
  * @return void
  */
 public function testExtension()
 {
     $this->assertTrue(Validation::extension('extension.jpeg'));
     $this->assertTrue(Validation::extension('extension.JPEG'));
     $this->assertTrue(Validation::extension('extension.gif'));
     $this->assertTrue(Validation::extension('extension.GIF'));
     $this->assertTrue(Validation::extension('extension.png'));
     $this->assertTrue(Validation::extension('extension.jpg'));
     $this->assertTrue(Validation::extension('extension.JPG'));
     $this->assertFalse(Validation::extension('noextension'));
     $this->assertTrue(Validation::extension('extension.pdf', array('PDF')));
     $this->assertFalse(Validation::extension('extension.jpg', array('GIF')));
     $this->assertTrue(Validation::extension(array('extension.JPG', 'extension.gif', 'extension.png')));
     $this->assertTrue(Validation::extension(array('file' => array('name' => 'file.jpg'))));
     $this->assertTrue(Validation::extension(array('file1' => array('name' => 'file.jpg'), 'file2' => array('name' => 'file.jpg'), 'file3' => array('name' => 'file.jpg'))));
     $this->assertFalse(Validation::extension(array('file1' => array('name' => 'file.jpg'), 'file2' => array('name' => 'file.jpg'), 'file3' => array('name' => 'file.jpg')), array('gif')));
     $this->assertFalse(Validation::extension(array('noextension', 'extension.JPG', 'extension.gif', 'extension.png')));
     $this->assertFalse(Validation::extension(array('extension.pdf', 'extension.JPG', 'extension.gif', 'extension.png')));
 }
開發者ID:alvaroziqar,項目名稱:galei,代碼行數:24,代碼來源:ValidationTest.php

示例5: extension

 /**
  * Check that value has a valid file extension.
  *
  * @param mixed $check Value to check
  * @param array $extensions file extenstions to allow
  * @return boolean Success
  * @access public
  */
 function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg'))
 {
     if (is_array($check)) {
         foreach ($check as $value) {
             if (Validation::extension($value, $extensions) === false) {
                 return false;
             }
             return true;
         }
     }
     $extension = strtolower(array_pop(explode('.', $check)));
     if (in_array($extension, array_map('strtolower', $extensions))) {
         return true;
     }
     return false;
 }
開發者ID:javierm,項目名稱:wildflower,代碼行數:24,代碼來源:validation.php

示例6: extension

 /**
  * Check that value has a valid file extension.
  *
  * @param mixed $check Value to check
  * @param array $extensions file extenstions to allow
  * @return boolean Success
  * @access public
  */
 function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg'))
 {
     if (is_array($check)) {
         return Validation::extension(array_shift($check), $extensions);
     }
     $extension = strtolower(array_pop(explode('.', $check)));
     foreach ($extensions as $value) {
         if ($extension == strtolower($value)) {
             return true;
         }
     }
     return false;
 }
開發者ID:michaelTadeu,項目名稱:nutriware,代碼行數:21,代碼來源:validation.php


注:本文中的Validation::extension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。