Forums

[resolved] Include an external PHP file in my post? (4 posts)

  1. smietan
    Member
    Posted 1 year ago #

    I am attempting to include an external php file in my post. Here is the PHP code I have in my post:

    <?php
    include('/wp-content/data.php');
    echo "fail";
    ?>

    I am running WP 3.0.1, and I have the Exec-PHP 4.1 plugin successfully installed. Yes, the link to data.php is valid. The PHP code appears to be working because the post always renders "fail". However, the include never shows up. The contents of the include file is html text, nothing fancy, just an unordered list, no other syntax, just raw html.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Try using the ABSPATH constant as part of the name to include:

    include(ABSPATH . 'wp-content/data.php');

  3. smietan
    Member
    Posted 1 year ago #

    Thanks for the suggestion.

    Oddly, replacing:
    <?php
    include('/wp-content/data.php');
    echo "fail";
    ?>

    With:
    <?php
    include(ABSPATH . 'wp-content/data.php');
    echo "fail";
    ?>

    Did not change the outcome. The text "fail" is still rendered on the page.

  4. smietan
    Member
    Posted 1 year ago #

    Actually, I had a typo. Your solution worked! This includes the contents of data.php successfully:

    <?php
    include(ABSPATH . 'wp-content/data.php');
    echo "fail";
    ?>

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic