Topic: Warning: readdir() expects parameter 1 to be resource

Hi guys

I'm experiencing various issues with CuteNews 1.5.3, so I thought I would check the error_dump.log. I has accumulated a massive number of the same error. It seems to be running in loop or something. It says:

Warning: readdir() expects parameter 1 to be resource, boolean given; /core/com/allow_full_story.php:35;

The relevant code is:

    // Article ID was not found, if we have not specified an archive -> try to find the article in some archive.
    // Auto-Find ID In archives
    //----------------------------------------------------------------------
    if (!$found)
    {
        echo '<a id="com_form"></a>';

        if (!$archive or $archive == '')
        {
            // Get all archives. (if any) and fit our lost id in the most propper archive.
            $lost_id        = $id;
            $all_archives   = false;
            $hope_archive   = false;

            if (!$handle = opendir(SERVDIR."/cdata/archives")) echo ("<!-- ".lang('cannot open directory')." ".SERVDIR."/cdata/archives --> ");

            while (false !== ($file = readdir($handle))) <------ ERROR IN THIS LINE
            {
                if ($file != "." and $file != ".." and !is_dir(SERVDIR."/cdata/archives/$file") and substr($file, -9) == 'news.arch')
                {
                    $file_arr = explode(".", $file);
                    $all_archives[] = $file_arr[0];
                }
            }
            closedir($handle);

            if ($all_archives)
            {
                sort($all_archives);
                if (isset($all_archives[1]))
                {
                    foreach($all_archives as $this_archive) if ($this_archive > $lost_id) { $hope_archive = $this_archive; break; }
                }
                elseif ($all_archives[0] > $lost_id)
                {
                    $hope_archive = $all_archives[0];
                    return FALSE;
                }
            }
        }

        if ($hope_archive)
        {
            $URL = $PHP_SELF.build_uri('archive,start_from,ucat,subaction,id', array($hope_archive));
            echo '<div>'.lang('You are now being redirected to the article in our archives, if the redirection fails, please').' [url=]'.lang('click here').'[/url]</div>
                    <script type="text/javascript">window.location="'.str_replace('&', '&', $URL).'";</script>';
        }
        else
        {
            echo '<div style="text-align: center;">'.lang('Cannot find an article with id').': <strong>'. (int)htmlspecialchars($id).'</strong></div>';
        }
        return FALSE;
    }

Re: Warning: readdir() expects parameter 1 to be resource

The code seems to be related to the achieve. I'm not using the archieve feature at all. Can I just delete this code to eliminate the php error?

Re: Warning: readdir() expects parameter 1 to be resource

Changing the error code line to

while ($file = readdir($handle))


might just do the trick https://cutephp.com/forum/style_emoticons/default/smile.gif