Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExcludeMimeType.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/File/MimeType.php';
26 
36 {
37  const FALSE_TYPE = 'fileExcludeMimeTypeFalse';
38  const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
39  const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
40 
44  protected $_messageTemplates = array(
45  self::FALSE_TYPE => "File '%value%' has a false mimetype of '%type%'",
46  self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected",
47  self::NOT_READABLE => "File '%value%' is not readable or does not exist",
48  );
49 
61  public function isValid($value, $file = null)
62  {
63  if ($file === null) {
64  $file = array(
65  'type' => null,
66  'name' => $value
67  );
68  }
69 
70  // Is file readable ?
71  #require_once 'Zend/Loader.php';
73  return $this->_throw($file, self::NOT_READABLE);
74  }
75 
76  $this->_type = $this->_detectMimeType($value);
77 
78  if (empty($this->_type) && $this->_headerCheck) {
79  $this->_type = $file['type'];
80  }
81 
82  if (empty($this->_type)) {
83  return $this->_throw($file, self::NOT_DETECTED);
84  }
85 
86  $mimetype = $this->getMimeType(true);
87  if (in_array($this->_type, $mimetype)) {
88  return $this->_throw($file, self::FALSE_TYPE);
89  }
90 
91  $types = explode('/', $this->_type);
92  $types = array_merge($types, explode('-', $this->_type));
93  foreach($mimetype as $mime) {
94  if (in_array($mime, $types)) {
95  return $this->_throw($file, self::FALSE_TYPE);
96  }
97  }
98 
99  return true;
100  }
101 }
_throw($file, $errorType)
Definition: MimeType.php:419
static isReadable($filename)
Definition: Loader.php:162
$value
Definition: gender.phtml:16
getMimeType($asArray=false)
Definition: MimeType.php:293