- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2021
09:14 PM
10-28-2021
09:14 PM
getting error Warning: Invalid argument supplied for foreach()
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
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2021
12:02 AM
11-06-2021
12:02 AM
Re: getting error Warning: Invalid argument supplied for foreach()
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; }
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2021
07:41 PM
11-08-2021
07:41 PM
Re: getting error Warning: Invalid argument supplied for foreach()
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; }
LitExtension - #1 Shopping Cart Migration Expert
LitExtension helps store owners and agencies migrate all important data from one eCommerce platform to another accurately, securely and at the highest speed.
Visit website: http://litextension.com/
LitExtension helps store owners and agencies migrate all important data from one eCommerce platform to another accurately, securely and at the highest speed.
Visit website: http://litextension.com/