本文整理匯總了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;
}
示例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;
}
示例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']);
}
示例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')));
}
示例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;
}
示例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;
}