WordPress.org

Ready to get started?Download WordPress

Forums

PHP Include on Page (10 posts)

  1. courtneyelizabeth
    Member
    Posted 8 years ago #

    Welp...I tried......

    First, I created a new page template...named it cams.php.
    and within the <div class=posts>
    I put:
    <?php include('cams/index.php'); ?>
    *cams/ directory is in the root directory of the website*

    Second, I created a page that used that template...and did not type anyting in the page text area....

    Third, I called the page....and well.....it gives me an fopen error when i know that the file exists because I can open up the directory and use the script fine. :(

    Please help.

    This is the script.

    http://www.urbanweblogs.com/cams/

    and this is the page i'm using to include the script.

    http://www.urbanweblogs.com/?page_id=3

  2. skippy
    Member
    Posted 8 years ago #

    The error is slightly misleading. It is not telling you that it cannot open cams/index.php. Rather, it's telling you that it cannot open head.tpl as called within cams/index.php

  3. courtneyelizabeth
    Member
    Posted 8 years ago #

    that's what i mean.....i know that head.tpl is there....because i can see it when i look at the script directly.

    http://www.urbanweblogs.com/cams/

  4. courtneyelizabeth
    Member
    Posted 8 years ago #

    i just dont get it.....maybe it's the way the index.php in the cams/ directory calls the head.tpl

  5. skippy
    Member
    Posted 8 years ago #

    It's very possible that the cams/index.php file is calling the head.tpl file, expecting it to be in the same directory as the calling application. In this instance, the calling application is actually one level above the cams directory.

    Perhaps the chdir() function might help?

  6. courtneyelizabeth
    Member
    Posted 8 years ago #

    like this?

    <?php

    // current directory
    echo getcwd() . "\n";

    chdir('cams/');

    // current directory
    echo getcwd() . "\n";

    ?>

  7. courtneyelizabeth
    Member
    Posted 8 years ago #

    it produces:

    /home/urbanweb/public_html /home/urbanweb/public_html/cam

  8. courtneyelizabeth
    Member
    Posted 8 years ago #

    EH...wasnt using my noggin...lmao....figured out how to use it...

  9. courtneyelizabeth
    Member
    Posted 8 years ago #

    the only thing with using "CHDIR" is that it wont use the "wrap-around" function....meaning, the links in the cams/ directory page..... IE. "Submit your cam" have to be hardcoded in the cam/ directory template AND because it's hardcoded....it doesnt include the WordPress header like a REGULAR include would....

  10. courtneyelizabeth
    Member
    Posted 8 years ago #

    would changing back to the original directory after the include help?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.