while I run bin/magento setup:upgrade its throwing below error
"Warning: Invalid argument supplied for foreach() in home/....../public_html/vendor/magento/module-media-storage/Model/File/Validator/NotProtectedExtension.php on line 84"
issue with import option also.
protected function _initProtectedFileExtensions(){ if (!$this->_protectedFileExtensions) { $extensions = $this->getProtectedFileExtensions(); if (is_string($extensions)) { $extensions = explode(',', $extensions); } foreach ($extensions as &$ext) { $ext = strtolower(trim($ext)); } $this->_protectedFileExtensions = (array)$extensions; } return $this; }
Does anyone have idea about this issue?
I used Magento 2.3.1, PHP 7.2
The error occurs because in the foreach expects the parameters as array , but it got empty or string.
Rewrite the code as :
protected function _initProtectedFileExtensions(){ if (!$this->_protectedFileExtensions) { $extensions = $this->getProtectedFileExtensions(); if (is_string($extensions)) { $extensions = explode(',', $extensions); } if (is_array($extensions) && !empty($extensions)) { foreach ($extensions as &$ext) { $ext = strtolower(trim($ext)); } } $this->_protectedFileExtensions = is_array($extensions) ? (array)$extensions : []; } return $this; }
protected function _initProtectedFileExtensions(){ if (!$this->_protectedFileExtensions) { $extensions = $this->getProtectedFileExtensions(); if (is_string($extensions)) { $extensions = explode(',', $extensions); } // check if don't array if (!is_array($extensions) ) { $extensions = []; } foreach ($extensions as &$ext) { $ext = strtolower(trim($ext)); } $this->_protectedFileExtensions = (array)$extensions; } return $this; }