简体   繁体   中英

PHP readdir() Error 500 Endless Loop

I have a script that works on the server I pay for. However when i try to install the same code under localhost i get this error on an endless loop.

PHP Warning: readdir() expects parameter 1 to be resource.

I looked around and some people say that is folder access, but it works on the remote server just not localhost where read and write access is 100%.

Could this be trigger by a setting in php.ini?

I mean other than that, I can't see anything else that will trigger this.

This is the code where the error points. But I don't think is the code since it works on one server but not the other. Correction I have now loaded this code on hostgator and it works fine also and on my securesignup server. Both work ok. Only localhost is getting this error.

 $upgraded_folder_path = $CFG['site']['project_path'] . "languages/" . $CFG['lang']['default'] . "/" . strtolower($value) . "/" . $upgraded_folder_name;
            if (!is_dir($upgraded_folder_path) && !($handle = opendir($upgraded_folder_path)))
                {
                while (false !== ($file = readdir($handle)))
                    {
                    if ($file == "." || $file == "..")
                        {
                        continue;
                        }
                    $file_name = $upgraded_folder_path . "/" . $file;
                    if (is_file($file_name))
                        {
                        require_once($file_name);
                        }
                    }
                closedir($handle);
                }

You're calling readdir() only when it's an invalid resource, ie - when it failed to open the directory:

 if (!is_dir($upgraded_folder_path) && !($handle = opendir($upgraded_folder_path)))

You can only read an existing directory and one that you can open. If you remove the ! from both of the conditions in that if -statement, it should work fine. Albeit, you also need to make sure the directory exists and your user has permission to read from it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM