Search code examples
phpincludeinclude-path

File exists but will not include with variable as path, not permission issue


I have a template that I am working on that generates dynamic content pulled in by dynamic includes. The problem is that although these include files exist (yes I check), they won't include or require and throw no errors even with error reporting. Here's the relevant code - notice that I am including other files in the same base directory with no issues i.e. nav.php.

        <div id="main-wrap">
            <div id="main" role="main">
                <section id="header-img">
                     <div id="rotator">
                        <div id="controls">
                            <div id="rotator-next"></div>
                            <div id="rotator-prev"></div>
                        </div>
                        <img src="<?php echo $BD; ?>img/index-header.jpg" width="3416" height="362" alt="">
                    </div>
                    <?php
                        if ($PAGE !== 'step2')
                        {
                            require_once 'inc/form-main.php';
                        }
                    ?>
                </section><!-- /#header-img -->

                <div class="clear"></div>

                <div id="inner-page-content" class="wide locations">
                    <div id="inner-page-inner">
                        <?php
                            $path = "inc/pages/$service/$location.php";

                            echo $path . '<br>';

                            if (file_exists($path))
                            {
                                require_once "inc/pages/$service/$location.php";

                                echo '<pre>'; print_r(error_get_last()); echo '</pre>';
                            }
                            else
                            {
                                require_once 'inc/404w.php';
                            }

Notice that I have tried using a concatted string, and also tried passing a var to require $path. Neither work and no errors are being thrown even though error reporting on. When I echo $path out it shows the correct path. I've checked the perms on the associated files and even directories, and they are all set properly.


Solution

  • Could it be related to your PHP include_path variable? Is the page perhaps trying to require the files in relevant to the current working directory rather than from the site root?