Skip to main content
Inspiring
December 17, 2018
Answered

Dreamweaver php template - wrong include path

  • December 17, 2018
  • 3 replies
  • 4951 views

I have a php template under root/template which is working as expected.

it has the following 'require_once' files :

<?php

require_once '../_scripts/functions.php';

require_once '../_scripts/pageMake/menuItems.php';

?>

<!doctype html>

<html lang="he" dir="rtl">

<head>

<!-- TemplateInfo codeOutsideHTMLIsLocked="true" -->

    <meta charset="utf-8">

<?php

require_once '../_scripts/pageMake/head.php';

The problem is that when i try to create a new php file from this template it get the wrong paths to these files:

When I create the new file, before savings the paths look like this:(I only show the include files)

require_once 'file:///C|/My%20Doc/Google%20Drive/DnD/Bootstrap_4/_scripts/functions.php'; 

require_once '../_scripts/pageMake/menuItems.php';

require_once 'file:///C|/My%20Doc/Google%20Drive/DnD/Bootstrap_4/_scripts/pageMake/head.php';

And after saving: (I only show the include files)

require_once '_scripts/functions.php'; 

require_once '../_scripts/pageMake/menuItems.php';

require_once '_scripts/pageMake/head.php';

It gets some of the paths wrong - in this case "../_scripts/pageMake/menuItems.php" should be "_scripts/pageMake/menuItems.php"

If i change the files order, e.g.

require_once '../_scripts/pageMake/menuItems.php';

require_once '../_scripts/functions.php';

I know get:

require_once '_scripts/menuItems.php'; 

require_once '../_scripts/pageMake/functions.php';

What is going on here and how to fix this so that all path will be generated correctly?

This topic has been closed for replies.
Correct answer karpiyon

yes,

i got:

Warning: include_once(): Failed opening '/C:/xampp/htdocs/_scripts/pageMake/menuItems.php' for inclusion (include_path='C:\xampp\php\PEAR')

and as i said, even this produces the same error (and yes,the file is there)

Warning: include_once(): Failed opening '/C:/xampp/htdocs/DnD_B4/_scripts/pageMake/menuItems.php' for inclusion (include_path='C:\xampp\php\PEAR') in


Ok,

I manages to solve this, so i hope as follows:

I have different root for html links and as follows:

function phpRoot()

{

    $host = $_SERVER['HTTP_HOST'];

$docRoot = $_SERVER['DOCUMENT_ROOT'];

if(strpos($host, "dnd-production.com") !== false){

#$site_Root = "http://$host";

$site_Root = $docRoot;

} else {

    $uri  = explode("/", $_SERVER['PHP_SELF']);

//print_r($uri);

$site_Root = "$docRoot/$uri[1]/";

}

return $site_Root;

} //phpRoot

function htmlRoot()

{

    $host = $_SERVER['HTTP_HOST'];

if(strpos($host, "dnd-production.com") !== false){

$site_Root = "http://$host";

} else {

    $uri  = explode("/", $_SERVER['PHP_SELF']);

//print_r($uri);

$site_Root = "//$host/$uri[1]/";

}

return $site_Root;

} //htmlRoot

This is working now though i do not understand why i need to use 2 different 'roots'?

Now,

I have another small issue regarding the html links and the "Visual media queries bar"

When i use this:

<link href="../css/mediaQuery.css" rel="stylesheet" type="text/css">

I see the Visual media queries bar.

When i use this:

<link href="<?php echo siteRoot()?>/css/mediaQuery.css" rel="stylesheet" type="text/css">

The css rules in the mediaQuery.css are applied but the Visual media queries bar is not shows. (I do press the button to show them)

Any reason why?

I also see the "mediaQuery.css" at the top of the panel as one of the open files and i can click it and see it's content.

3 replies

karpiyonAuthor
Inspiring
December 18, 2018

thank you

no i do not have any alias.

B i r n o u
Legend
December 19, 2018

so I think that the problem is there... your XAMPP server doesn't point to the right location...

2 solutions... you should try to have your web site located in an appropriate root.

A - move your web site in the native htdocs XAMPP folder

or B - create an alias... I think that creating an alias should be the more easy way to go...

karpiyonAuthor
Inspiring
December 19, 2018

Are you sure this is how it works?

I have 3 testing servers under xampp/htdocs.  i created the folders DnD_B4, DnD_Responsive & TEST myself and specified it in DW

i can't move all of them under the same root?

or am i doing something wrong when specifying the path in DW?

karpiyonAuthor
Inspiring
December 18, 2018

Ok,

I but if I just use include, no template I get to path problems again.

I may put php pages in different directories but i want to include files relative to the site root.

simply putting "/" in front of the path does not work.

site root, relative.

<?php include("../../_scripts/nav.php") ?> is working but i'd rather not use it due to the problems i reported.

<?php include("/_scripts/nav.php") ?> does not work even tough "/" should be treated as site root and _scripts dir is under site root.

I tried to generate the site root like show below. This has been working for year both on my testing server and real server.

i am using this so that i do not need to change anything when i upload to the server.

$host = $_SERVER['HTTP_HOST'];

if(strpos($host, "dnd-production.com") !== false){

$site_Root = "http://$host";

} else {

    $uri   = explode("/", $_SERVER['PHP_SELF']);

//print_r($uri);

$site_Root = "//$host/$uri[1]/";

}

$file = $site_Root."/_scripts/nav.php";

i get this error:

Warning: require_once(//localhost/mySite/_scripts/nav.php): failed to open stream: No such file or directory in

To remove any doubt that my $site_Root is correct i can say that when i use it, in the same page, on html links it is working. This is working:

<link href="<?php echo siteRoot()?>/css/mediaQuery.css" rel="stylesheet" type="text/css">

So again, what is going on with php links???

Jon Fritz
Community Expert
Community Expert
December 17, 2018

DW doesn't know, until you save the Child page, where you'll be saving it, so it can't use a Document Relative link until that happens. Up until you save, it will show the full absolute path.

I've never run into DW writing in the wrong paths with a properly defined site. We would have to see your directory structure to say whether those new links are actually wrong.

From within a Template folder, it would make sense to see the ../ moving up one level to get out to your _scripts folder and include files. Unless you're also saving the Child pages to another folder at the same level as the Templates folder, there may be no reason for the leading ../ and the link may actually be correct as rewritten by DW.

karpiyonAuthor
Inspiring
December 17, 2018

I know DW writes the correct path only after i save the file locally.

This is why i showed the file before and after saving locally,

It gets the file wrong and as i showed, if i change the order of the file that it show another file with wrong path.

only 1 file of the 3 in the example i showed gets a wring path.

anything i can do to understand why or fix it?