• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dreamweaver php template - wrong include path

Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

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?

Views

3.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Dec 18, 2018 Dec 18, 2018

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, "d

...

Votes

Translate

Translate
Community Expert ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

i also showed the file before it is saved and, in it, you can see that 2 files get the correct full path before saving and 1 file is left with the relative location as the template:

'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';

can this be due to some problem regarding the "require" command with the php template?

i never experienced this with html templates.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

You're using Google Drive as your local site folder???

Nancy O'Shea— Product User, Community Expert & Moderator

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

that was just for sync purposes.

I have the same problem on my local drive.

n any casa the Google drive is where those files where stored but the testing server is local.

The live view for the template is working fine.

is is only when I try to create anew file based on this template that i get this wrong links.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

this problem is with most of the <?php include ....?>

not with html links in the template

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

could you test this on your side???

create a new php template

  • file>new>new document>php template
  • name it test.dwt.php
  • in the new template, just add 3 require or include statement:

<?php

require_once('../aaa/test1.php');

require_once('../aaa/test2.php');

require_once('../aaa/test2.php');

?>

save and try to generate a new php from this template - do all the include point to the right path?

THANKS!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

It is true that Dreamweaver has a problem with links inside, not only PHP, but also inside JS.

I do a find and replace in those situations.

Perhaps it would be best to address this problem where it can be rectified, by going to the Help menu item -> report bug etc...

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

I guess I neever noticed it before because with PHP files, I don't have much need for DW Templates.

Nancy O'Shea— Product User, Community Expert & Moderator

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

What is the "best practice" regarding these php includes in  a site i am creating?

I am now migrating my site to bootstrap 4 and considering using php includes instead of templates but i do have some problems with the links as you saw.

Especially since pages my reside on different folders at different depths.

I need something which will work for my testing server AND when i upload the real site without the modifying anything.

Thanks,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

once I had trouble when porting an application on different server... and depending on the server setting I had always to adapt... so I used this way to include, and it worked... perhaps give it a try

<?php

    include_once('/'.trim( $_SERVER['DOCUMENT_ROOT'], '/' ).'/shared/php/__SESSION__.php');

?>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

Thank you,

I am using xampp testing server and there is no "shared/php" under the site root on the testing server neither on the remote one.

i tried pasting your code and got an error regarding file not found.

Again. i want to emphasis that i can get links to work relative to site root using the method i described above but it only works for html links, not php. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

Sorry for the misleading induction... in fact I was giving an example of a path...

personally I often use servers sharing resources for various aspects of the application... hence the shared folder and in addition the php folder...

so no matter where your resources are to be included... let's imagine that the folder is called RESOURCES and the file to be included is called FUNCTIONS.PHP

from all other files in your application, when you want to include the FUNCTIONS.PHP file, you should then reference it this way

<?php

    include_once('/'.trim( $_SERVER['DOCUMENT_ROOT']," /').'/RESOURCES/FUNCTIONS.PHP');

?>

note that for this example I used capital letters for the names of folders, files and extensions, but you are free to use both capital letters and/or small letters, however be aware that the server will be case sensitive (in most cases) and therefore it is important to respect the way in which folder names, files and extensions are written at file level and at path level.... use the same

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Are you assuming all files are under the same site root?

$_SERVER['DOCUMENT_ROOT'] points, in my case to "C:/xampp/htdocs"

This is not the site root which is:"C:/xampp/htdocs/DnD_B4"

But even if i add:

include_once('/'.trim( $_SERVER['DOCUMENT_ROOT'],' /').'/DnD_B4/_scripts/pageMake/menuItems.php');

I still get the same error.

Are you sure this still works in new version pf DW?

Perhaps it has to do with xampp configuration?

And again...

This works just fine:

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

where siteRoot() is:

function siteRoot()

{

    $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;

} //siteRoot

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

have you try

include_once('/'.trim( $_SERVER['DOCUMENT_ROOT'],' /').'/_scripts/pageMake/menuItems.php');

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

could just post a screen shot of your folders tree ?

think to let open the folder conatining the include, and the one containing the file to be include

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Gladly. only to which of the problems are you referring?

The problem with php include or the missing Visual media queries bar?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

this thread is about the include problem.. isn't it ? or did I miss something ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Well, yes.

Still the initial problem is now solved with the combination of 2 functions to generate root.

1 for PHP and 1 for html though i think 1 is enough for the actual web server, for my testing xampp server i need 2:

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

I'll open anew thread for the other question.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

this one?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

thanks,

yes this one...

so you said that you was using XAMPP, and that your root was located in c://xampp/htdocs... and when I see your file panel , I can see your site located c://users/chopi and so on... so I think that you have a root folder trouble... or did you wrote any aliases FILE.CONF for being handle by XAMPP to relocate the htdocs root outside of the original WWW one ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

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???

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines