When I upload a product image the file uploads fine but on completion magento then shows this error:

Warning: Invalid argument supplied for foreach() in ..../app/code/core/Mage/Core/Model/File/Validator/NotProtectedExtension.php on line 91

I have checked that there the protected_extensions node is present in


And also I have grepped for protected_extensions across the whole site so I know this is not being interfered with elsewhere.

This link : http://www.codegithub.com/watch?v=CBN6qgxxgUxX suggested that the presence of a null value for the

path => 'general', value => NULL

in the core_config_data table stops something working but deleting this didn't help. It doesn't suggest further actions and I don't understand how to investigate that further.

Can anyone advise ways to resolve where this problem has come from. The site was working fine until recently and can't identify any changes we have made that would have this affect.

UPDATE: Have tried disabling all extensions but that doesn't help, can anyone point me to where I can get more understanding of this aspect of the system I am bogged down in terms of understanding how this is happening.

UPDATE2: SQL query suggested below does return no records as suggested. config.xml is also as it should appear.


returns null not array so to get the site working I have hacked the validator function to check for an array but this has effectively disabled the protected files function so I need to resolve this in the long term.

this is defined as the constant in getProtectedfileExtensions:

const XML_PATH_PROTECTED_FILE_EXTENSIONS= 'general/file/protected_extensions';


Mage::getStoreConfig(self::XML_PATH_PROTECTED_FILE_EXTENSIONS, $store);

returns null not any kind of array.

In desperation I even tried changing config.xml to 775 just in case there was some permissions issue.

I feel like I am missing some piece of understanding about magento config, anyone suggest the next step?

  • hi frinds It could be because of some extension you installed. I had the same issue, but after removing the extension it worked. Aug 30, 2015 at 7:16
  • Hi Ashvin, thank you for answering. I tried disabling all extensions by changing the .xml config file to .xml.OFF but no joy. Still had the same problem. Any ideas on how I can track down where this is happening? Aug 30, 2015 at 20:54

2 Answers 2


If you initialize Mage, like this for example:

    define('MAGENTO_ROOT', isset($rootDir) ? realpath($rootDir) : dirname(dirname(__FILE__)));
    $mageFilename = isset($bootStrap) ? $mageFilename : MAGENTO_ROOT . '/app/Mage.php';
    $bootStrap    = isset($bootStrap) ? $bootStrap : MAGENTO_ROOT . '/app/bootstrap.php';

    if ($bootStrap !== false and file_exists($bootStrap)) {
      require_once $bootStrap;
    require_once $mageFilename;


And than try this:


Does it say it's: null or object ? (Thus no string or array ?)

The code you talking about:

// Mage_Core_Model_File_Validator_NotProtectedExtension
    protected function _initProtectedFileExtensions()
        if (!$this->_protectedFileExtensions) {
            /** @var $helper Mage_Core_Helper_Data */
            $helper = Mage::helper('core');
            $extensions = $helper->getProtectedFileExtensions();
            if (is_string($extensions)) {
                $extensions = explode(',', $extensions);
            foreach ($extensions as &$ext) { // <-- Line 91 !
                $ext = strtolower(trim($ext));
            $this->_protectedFileExtensions = (array) $extensions;
        return $this;

const XML_PATH_PROTECTED_FILE_EXTENSIONS = 'general/file/protected_extensions';
public function getProtectedFileExtensions($store = null)
    return Mage::getStoreConfig(self::XML_PATH_PROTECTED_FILE_EXTENSIONS, $store);

Core/etc/config.xml should look like this:

            <!-- PHP script file extension -->
            <!-- File extension of configuration of an Apache Web server -->
            <!-- Java script file extension -->
            <!-- Perl script file extension -->
            <!-- Python script file extension -->
            <!-- Active Server Page script file extension -->
            <!-- UNIX command prompt file extension -->
            <!-- Common Gateway Interface script extension type -->
            <!-- BOF HTML file extensions -->
            <!-- EOF HTML file extensions -->

And this query should not return records:

SELECT *  FROM `core_config_data` WHERE `path` LIKE 'general/file/%'

Good luck and happy hacking.

  • 1
    thanks for the pointers Roger, this is really helpful to give me a heads up of how to move it forward. Sep 18, 2015 at 7:10
  • 1
    i have updated the question above. The suggestion to instantiate mage was very useful as a way of debugging variables, I don't know why this didn't occur to me but it didn't Sep 18, 2015 at 8:53
  • I'm using: en.wikipedia.org/wiki/Test-driven_development for writing Magento modules. Sep 18, 2015 at 12:04

Sorry, but i can't comment because my reputation isn't high enough... So, hope your going to read this.

I don't know how far this 'warning' is down the application flow. Magento is configuration based and event driven. So, if your you configuration system is corrupted, then it will result in somethings like this. But your configuration is loaded and used very early in the application flow, so it would be strange to me.

If your intressed how the configuration system works your really have to read this: http://alanstorm.com/magento_config_a_critique_and_caching and maybe buy his book, to support hiim.

So: This warning could be a symptom of a underlaying problem in the configuration part of Magento. Like does your config store node has a 'copy' of the default xml ?

Do not focus to mutch on the problem it self, because this could be a side-effect. https://en.wikipedia.org/wiki/Side_effect_(computer_science)

Maybe a quick 'sanity' check:

file_put_contents('<?xml version="1.0" ?>'.

Open with a good xml editor and look if all 'stores' are there and the store your using with the public function getProtectedFileExtensions($store = null) function. Does it really use the 'default' with null for example ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.