• Using WordPress MU.

    I am trying to reference a file located in an individual blog’s blog.dir/files directory.

    in header.php for the THEME, I added:

    <?php include (get_bloginfo('url') . '/files/test.html'); ?>

    I know it’s the right path and a direct link to it works. What am I doing wrong? I need to be able to include the TXT that’s in that file.
    I’ll have this file in multiple blogs.dir/files folders.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Try this…

    <?php
    $url=get_bloginfo('url');
    include($url. '/files/test.html'); ?>

    I don’t think include likes the variable in it for some reason.

    I’ll have this file in multiple blogs.dir/files folders.

    Why not just put it in one spot? Or will they all be different?

    Thread Starter jmwebguy

    (@jmwebguy)

    Ipstenu, I tried that before I posted. Just tried again and it didn’t work. I can even do an echo write on that $url plus the file location and it points out the right location.

    Andrea, They will all be different. I am putting ad tags in them and figured this would be the easiest way. I will put one in the header and one in the footer.

    I can’t figure out why this is so difficult. Even if I put the full url in the include, it doesn’t work. It’s like it’s ignoring it, yet other includes (in the single.php) works.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Even if I put the full url in the include, it doesn’t work.

    … Wait a second.

    What’s the FULL URL you’re trying to use? Is it like domain.com/subsite/files/test.html or domain.com/blogs.dir/2/files/test.html ?

    Hy,

    I have also the same problem,
    Like jmwebguy, I want to includes php files witch are located in the parent directory of the Blog

    I’ve tried <?php include (get_bloginfo(‘url’) . ‘/myfile.php’); ?> first and <?php include (‘../../../../../myfile.php’); ?> next

    the problem is the same.

    the only include, seams to work, is when header.php and the other file are in the same directory.

    Any idea ?

    I have found the solution right here :
    http://wordpress.org/support/topic/include-php-files-at-absolute-urls?replies=5

    you have to write your incude like this :
    <?php include(ABSPATH . “../myfile.php”); ?>

    ABSPATH is the root of your wordpress blog

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    You can also use get_bloginfo( 'wpurl' ) 🙂 You were VERY close with your ‘url’ call!

    <?php include( get_bloginfo( 'wpurl' ) . "/myfile.php"); ?>

    include() with a URL will only work under certain specific circumstances on a server (and even then, IIRC, if you are including a PHP file, it will include the parsed version rather than the raw PHP code). include() and require() statements should always use paths (/var/www/…) rather than URLs if you want them to work consistently and properly.

    EDIT – You can read a little more about what I mentioned above by reading the second paragraph below Example #2 on the PHP doc page for the include() function.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘php include not working in Header.php’ is closed to new replies.