本文整理汇总了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;
}