• The following ZYZ PHP snippet:

    $global $SOUNDBITEDIRECTORY_;
    $dh = opendir($SOUNDBITEDIRECTORY_);

    while (false !== ($entry = readdir($dh))) {
    echo “$entry\n”;
    }

    … causes a “500 Internal Server Error” when trying to save the Page on Word Press. Removing the while loop, and the WP page saves okay.

    If I save the WP page without the while loop (it saves okay – so the shortcode has been saved). If I then put the while loop back into the snippet, the WP page will not save but, as the snippet short code is there, the page will function as expected and all the files in the directory will display.

    I have also tried scandir with similar results. Other pages that I have developed (which do not use scandir or readdir) function as expected.

    I even tried deleting and reinstalling the plugin.

    Does anybody know if I am doing something wrong or whether scandir/readdir are part of the problem?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter graham998

    (@graham998)

    After spending about two days trying to resolve this it appears that the directory (in this case via the global variable – $SOUNDBITEDIRECTORY_) has to be the full path name and not the a relative pathname.

    Not sure why it gives a 500 Internal Server Error when saving the WP page, but the code still functions correctly.

    The problem, of course, is that I could live with the code working but when you need to update the snippet (or any other snippet on that page), you can no longer save it – so it needed resolving.

    Moderator threadi

    (@threadi)

    In what condition are you running the code? Are you using a WP hook like init or wp for this?

    Thread Starter graham998

    (@graham998)

    It’s the XYZ snippet plugin and the shortcode is entered onto the web page.

    Moderator threadi

    (@threadi)

    You mean this plugin? https://ww.wp.xz.cn/plugins/insert-php-code-snippet/ – if you can’t update the code in this one, I would recommend you contact their support forum for clarification.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘XYZ Code Snippet causes 500 internal server error when using readdir’ is closed to new replies.