Пример #1
0
 /**
  * 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
0
 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
0
 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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;
 }