Link to home
Start Free TrialLog in
Avatar of nzrubin
nzrubinFlag for New Zealand

asked on

keep path in including file

Hello Guys
little question!
is it possible to keep paths on remote file that i include in other page?
for exmpl  i include file
include ("../../TextEditor/examples/textEditor.php");
but the file textEditor.php has his own links to remote files like
<script language="JavaScript" type="text/javascript" src="../cbrte/html2xhtml.js">
</script>
<script language="JavaScript" type="text/javascript" src="../cbrte/richtext_compressed.js"></script>

and when i include file in some page the file (of course) doesnt work properly cos it lost paths to java files
Avatar of mr_egyptian
mr_egyptian
Flag of United States of America image

Try specifying everything from your document root ( / )

<?php
    include ($_SERVER['DOCUMENT_ROOT'].'/TextEditor/examples/textEditor.php');
?>
 
-or-
 
<?php
    include ('/TextEditor/examples/textEditor.php');
?>
 
------------------------
 
<script type="text/javascript" src="/cbrte/html2xhtml.js"></script>
<script type="text/javascript" src="/cbrte/richtext_compressed.js"></script>

Open in new window

Avatar of Lordgobbledegook
Lordgobbledegook

If the links in textEditor.php are other PHP files then they are relative to the included file.  However, as you are outputting Javascript then you will need to change your paths in textEditor.php so they are relative to the original script that is making the call.

If you have multiple scripts in multiple areas that call textEditor.php then you will need the change the links in textEditor.php to something like:


<script language="JavaScript" type="text/javascript" src="/directory/structure/cbrte/html2xhtml.js">
 
OR
 
<script language="JavaScript" type="text/javascript" src="http://www.xxx.xxx/directory/structure/cbrte/html2xhtml.js">
 
OR
 
echo '<script language="JavaScript" type="text/javascript" src="' . $_SERVER['DOCUMENT_ROOT'] . '/directory/structure/cbrte/html2xhtml.js">';

Open in new window

Is there an echo inn here? ; )

Actually, don't use my second php example as the / is only good for client side.  And don't use $_SERVER['DOCUMENT_ROOT'] for javascript, as it is the absolute path from root on the server.
ASKER CERTIFIED SOLUTION
Avatar of mr_egyptian
mr_egyptian
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial