PageRenderTime 72ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/library/Zend/Validate/File/ExcludeExtension.php

http://firephp.googlecode.com/
PHP | 94 lines | 38 code | 9 blank | 47 comment | 9 complexity | 9995f6ebd5e845dc6b69af38da54b29b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Validate
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: $
  20. */
  21. /**
  22. * @see Zend_Validate_Abstract
  23. */
  24. require_once 'Zend/Validate/File/Extension.php';
  25. /**
  26. * Validator for the excluding file extensions
  27. *
  28. * @category Zend
  29. * @package Zend_Validate
  30. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension
  34. {
  35. /**
  36. * @const string Error constants
  37. */
  38. const FALSE_EXTENSION = 'fileExcludeExtensionFalse';
  39. const NOT_FOUND = 'fileExcludeExtensionNotFound';
  40. /**
  41. * @var array Error message templates
  42. */
  43. protected $_messageTemplates = array(
  44. self::FALSE_EXTENSION => "The file '%value%' has a false extension",
  45. self::NOT_FOUND => "The file '%value%' was not found"
  46. );
  47. /**
  48. * Defined by Zend_Validate_Interface
  49. *
  50. * Returns true if and only if the fileextension of $value is not included in the
  51. * set extension list
  52. *
  53. * @param string $value Real file to check for extension
  54. * @param array $file File data from Zend_File_Transfer
  55. * @return boolean
  56. */
  57. public function isValid($value, $file = null)
  58. {
  59. // Is file readable ?
  60. require_once 'Zend/Loader.php';
  61. if (!Zend_Loader::isReadable($value)) {
  62. return $this->_throw($file, self::NOT_FOUND);
  63. }
  64. if ($file !== null) {
  65. $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
  66. } else {
  67. $info = pathinfo($value);
  68. }
  69. $extensions = $this->getExtension();
  70. if ($this->_case and (!in_array($info['extension'], $extensions))) {
  71. return true;
  72. } else if (!$this->_case) {
  73. $found = false;
  74. foreach ($extensions as $extension) {
  75. if (strtolower($extension) == strtolower($info['extension'])) {
  76. $found = true;
  77. }
  78. }
  79. if (!$found) {
  80. return true;
  81. }
  82. }
  83. return $this->_throw($file, self::FALSE_EXTENSION);
  84. }
  85. }