1 Reply Latest reply: Jul 25, 2009 2:45 AM by David_Powers RSS

    Fails to open connection stream

    Mike_Watt Community Member

      Ok, so have a page that works wonderfully where it currently sits (off the HTTP_ROOT).

       

      It includes the line:

      <?php require_once('/Connections/imaging101.php'); ?>

       

      I decided I wanted to move this page, along with a few others that are all "admin only" to an "admin" directory.  I moved the pages and DW automatically updated the above string to:

       

      <?php require_once('../Connections/imaging101.php'); ?>

       

       

      I expected this to work, but it does not... I constantly get the error:

       

      Warning: require_once(Connections/imaging101.php) [function.require-once]: failed to open stream: No such file or directory in /home/content/d/j/m/djmikewatt/html/sites/imaging101/includes/left_pane.php on line 1

      Fatal error: require_once() [function.require]: Failed opening required 'Connections/imaging101.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/d/j/m/djmikewatt/html/sites/imaging101/includes/left_pane.php on line 1

       

       

      I tried adjusting the string to things like:

       

      <?php require_once($_SERVER['HTTP_HOST'].'/Connections/imaging101.php'); ?>

      <?php require_once($_SERVER['DOCUMENT_ROOT'].'[path from root]/Connections/imaging101.php'); ?>

      None of this works. I don't know what is wrong.  If the page works off the root, and then is places one level deep ([root]/admin/) shouldn't simply adding the ".." in front of the path do the trick? (../Connections/imaging101.php)

       

      Am I missing something else here?

        • 1. Re: Fails to open connection stream
          David_Powers CommunityMVP

          Thread moved to Dreamweaver Application Development forum, which deals with server-side issues.

           

          The PHP include and require commands use document-relative paths or look for files in your PHP include_path. They do not understand links relative to the site root. It would appear that the previous location of your include file just happened to translate correctly to the location of the include file. Now that you have moved it, PHP can't find it.

           

          The reason $_SERVER['HTTP_HOST'] doesn't work is because most hosts turn off the inclusion of files through a URL. In fact, it's the default setting in PHP since 5.2.

           

          I don't know why  $_SERVER['DOCUMENT_ROOT'] doesn't work, but it's not supported on all servers, so that might be the problem.

           

          There are two simple ways to solve this problem:

          • Use an absolute path, starting with /home/content/ etc.
          • Use set_include_path() to add the folder where the file resides in your include_path.