I have a main.php file which has the following three included php files:
<!--TAB 1--->
<?php include "tab1.php"; ?>
<!--TAB 2--->
<?php include "tab2.php"; ?>
<!--TAB 3--->
<?php include "tab3.php"; ?>
When I open main.php in Dreamweaver, I have access to these 3 included files. My question is: What about files that are included inside one of these include files?
For example, the tab2.php file reference these php files:
<?php include "a.php"; ?>
<?php include "b.php"; ?>
<?php include "c.php"; ?>
In order to be able to edit these included files which are inside another include file, what needs to be done? Will I need to open those directly?
What I would like to be able to do is open main.php and then be able to add all 6 included files:
tab1.php
tab2.php
tab3.php
a.php
b.php
c.php
It seems as though I only have direct access to the first-level include files. Any suggestions? Thanks.
If you're using Dreamweaver CS5, it has an (default enabled) option to show includes in a line below the file tabs. If you have an include that has other includes, the only way of editting this includes directly from this file is to press CTRL+D in the include, then Dreamweaver will show a popup for you to select the includes to edit and it will open the selected one in a tab.
Related
I've been having issues with my PHP include function. So can anyone explain to me why this would work...
//testfile1.php
<?php
include 'file1.php';
?>
//testfile2.php
<?php
include 'file2.php';
?>
but this will NOT work..
//testfile.php
<?php
include 'file1.php';
include 'file2.php';
?>
Is there anyway to include the second file within the main file? I'm suppose to streamline two php files into one main file and run that. (All files are on the same directory and can 'see' each other no problem.)
Try changing your include statements to include_once. Look for includes within your included files and change them also.
If file1.php also includes file2.php itself, and file 2 had a function declaration, you could be re-declaring a function with the same name.
Looks like you're overlapping include with files which are probably being included twice or not at all. In this case you need to use either
include_once() instead of include()
You can also use
require_once() instead of include() //use this option if the include is required
I have a file here: public_html/wiki/index.php
Im calling these files:
<?php
include "../auth.php";
include "../header.php";
?>
However, my page looks like this:
If I paste the same file in public_html/index.php then it will look like this:
I think I've narrowed it down to my header.php file which is being called from /wiki/ but header calls files from ../css.. and ../js and so on.
How can this be adressed? I've looked at many posts already which tells me to define a global variable but it doesn't help me. Like so:
<?php //config file in root folder
define("ROOT", __DIR__ ."/");
?>
and then calling them with this:
<?php
include_once("../config.php");
include (ROOT ."auth.php");
include (ROOT ."header.php");
?>
How should I do this so I can get all my javascripts and the actual site with me in another folder?
NOTE: I WANTED THIS AS A COMMENT BUT DO NOT HAVE THE REP
We have a different folder structure, but it is good practice to put your includes in one folder and from there link all the JS files (best practice is, place them in a pre-footer for speed) and then do
<?php include $_SERVER['DOCUMENT_ROOT'].'/includes/page-footer.php'; ?>
Just change the file name to suit you :) hope this helps
the problem was my include file didnt specify links as /js/file.js
i had them as js/file.js.
thanks #cd001
Hey I would like to include a navigation.php file in my website, but i cant figure out how to include an external file in a .php file, and the only way i could find to include the navigation.php into the files was to make a copy of it in each directory.
<?php include("navigation.php"); ?> works when i make a copy of the navigation.php in each directory.
<?php include("http://www.mysite.net/format/navigation.php"); ?> gives me an error.
I would like to only have one of these navigation.php files in a "Format" directory and then make each page fetch the file and display it.
Also ill be monitoring this question for a while so just ask me if you need any additional info.
Put that file one place. Then refer to it in each file by its proper path.
// navigation.php is in the same directory
<?php include("navigation.php"); ?>
<?php include("./navigation.php"); ?>
// navigation.php is one directory below the current directory
<?php include("../navigation.php"); ?>
// navigation.php is two directories below the current directory
<?php include("../../navigation.php"); ?>
But this can get tedious if you have lots of files in lots of directories. The best way to do this is to use the full path to the file on the file system:
// Full path relative to the root of the account
<?php include("/full/path/to/navigation.php"); ?>
But this can get tedious if the path changes. So define a variable or constant to hold that value for you so you only need to change it in one place:
// In a config file
define('INCLUDE_PATH', '/full/path/to/');
// In each page after you include your config file
<?php include(INCLUDE_PATH . "navigation.php"); ?>
I'm trying to include other page from other folder. and i tried this and it won't show the "side.php"
<?php
include 'side.php';
?>
And the "side.php" has:
home
Well you have the answer to your question inside your question.
" Im trying to include other page from other folder"
It means that you have to go inside that folder in order to access the file
<?php
include 'folder_name/side.php'
?>
or just copy the side.php file where your working file is so that all files are in one place
Maybe I'm wrong because I don't know php so it might not work but you could check this out
Include PHP file into HTML file
Problem is very simple.. It would seem.
Error:
Warning: include(includes/navigation.php): failed to open stream: No such file or directory in C:\xampp\htdocs\sub_page\about.php on line 27
Warning: include(): Failed opening 'includes/navigation.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\sub_page\about.php on line 27
I am redoing a site. Currently I am splicing it into PHP. Same way I have also ways done. Except this time I am making it more structured. Example of my code.
<!-- Start Navigation -->
<?php include 'includes/navigation.php'; ?>
<!-- End Navigation -->
<!-- Start Top Menu -->
<?php include 'includes/top_menu.php'; ?>
<!-- End Top Menu -->
<!-- Start Promo Menu -->
<?php include 'includes/pro_menu.php'; ?>
<!-- End Promo Menu -->
So lets that the file navigation is in includes folder which is located in the root. Lets say that the code above is on the services page which is '2' levels in. Not 1'. Typically i have it only '1' lvl of dir in so simply changing
<?php include 'includes/navigation.php'; ?>
to this
<?php include '../includes/navigation.php'; ?>
worked fine.
The above code is on the services page which is located at
/sub_page/services/services.php
If i moved the services.php file from the above dir path to 1 lvl close to root like so
/sub_page/services.php
and change the path on the include to
<?php include '../includes/navigation.php'; ?>
it works fine. I need to be able to call the files from anywhere. Does anyone know how to do this? Thanks!
EDIT: Will use the following as an example. I was pulling a path error on this line
<?php include 'sub_page/about_us/includes/meta.php'; ?>
I was able to use the following instead
<?php include __DIR__ . "/includes/meta.php"; ?>
to fix it. However if i tried to add or take away a directory level from the path it would again return an error. The same thing will not work for any of the other lines/paths.
before
<?php include 'includes/navigation.php'; ?>
after
<?php include __DIR__ . "/navigation.php"; ?>
Any idea?
Set an include path for PHP to "look" for these files: http://php.net/manual/en/function.set-include-path.php or use an absolute path.
If I understand you correctly you want to include a file (services.php) in other files which are on different levels. The included file itself includes some other files.
You must use absolute paths in services.php, e.g.
include __DIR__ . "/navigation.php";
Then it is irrelevant from which directory level you include services.php. __DIR__ will always have the correct path of services.php, no matter where services.php is included.
EDIT: Maybe even clearer...
Assuming directory tree:
<htdocs>/index.php
<htdocs>/includes/meta.php
<htdocs>/includes/navigation.php
<htdocs>/sub_page/about.php
navigation.php is to be included by meta.php.
meta.php is to be included by index.php and about.php.
Paths for includes:
meta.php: include __DIR__ . "/navigation.php";
index.php: include "includes/meta.php";
about.php: include "../includes/meta.php";
Any other file can now include meta.php with a path depending on its directory level.
The __DIR__ in meta.php will always provide the correct path to navigation.php.