dreamMyDream2014 2013-01-09 14:10
浏览 48
已采纳

PHP readdir()错误500无尽循环

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);
                }
  • 写回答

1条回答 默认 最新

  • dongrao1862 2013-01-09 14:13
    关注

    You're calling readdir() only when it's an invalid resource, i.e. - 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料