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.

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

报告相同问题?

悬赏问题

  • ¥50 求fpga交通信号灯设计Verilog代码
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人