473,473 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Include problem

Hi, I'm currently writing website using php. My problem is, when I do:

include("../../library/file.php"); // this is from e.g
/level1/level2/something.php

it works. However, when I use:

include("../../../library/file.php"); // and this one from
/level1/level2/level3/something.php

it doesn't work. So, does the include statement in php only cover 2
upwards directories? Is there anyway around this?
Thanks.
Nic
Jul 17 '05 #1
2 2421
Kupo wrote:
My problem is, when I do:

include("../../library/file.php");
// this is from e.g /level1/level2/something.php

it works. However, when I use:

include("../../../library/file.php");
// and this one from /level1/level2/level3/something.php

it doesn't work.
/How/ does it not work?

it includes a different file? :)
it gives a error message? ==> try error_reporting(E_ALL);
what is the error message?
it just ignores the include()?
So, does the include statement in php only cover 2
upwards directories?
No.
Is there anyway around this?
Maybe if you specify the path from the root

include '/library/file.php';

no matter how deep you are in the directory structure.
Thanks.


It works for me:

$ cat /home/pedro/src/php/test.php
#!/usr/bin/php
<?php
error_reporting(E_ALL);
include 'inc.php';
include '../php/inc.php';
include '../../src/php/inc.php';
include '../../../pedro/src/php/inc.php';
include '../../../../home/pedro/src/php/inc.php';
include '../../../../../../../../../home/pedro/src/php/inc.php';
echo "Done!\n";
?>

$ cat /home/pedro/src/php/inc.php
<?php
echo "inside included file\n";
?>

$ cd /home/pedro/src/php
$ ./test.php
inside included file
inside included file
inside included file
inside included file
inside included file
inside included file
Done!

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

<Kupo> wrote in message news:qt********************************@4ax.com...
Hi, I'm currently writing website using php. My problem is, when I do:

include("../../library/file.php"); // this is from e.g
/level1/level2/something.php

it works. However, when I use:

include("../../../library/file.php"); // and this one from
/level1/level2/level3/something.php

it doesn't work. So, does the include statement in php only cover 2
upwards directories? Is there anyway around this?
Thanks.


Have a play with getcwd() to find out where you are, and work it from there.
Then you have to worry about permissions, chroot jails, etc.

Garp
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Yannick Turgeon | last post by:
Oups! I did a typing error in my last post. Fixed. ----------- Hello all, We are currently changing our web server and, in the process, updating PHP version from 4.3.0 to 4.3.5. The problem...
43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
6
by: alan | last post by:
Dear all, I have written my own function by C. And my development platform is W2k with VC6.0. Then I also defined a header file to extern declare this function. After that, I include this...
6
by: atv | last post by:
Alright, i have some questions concerning include files en global variables.I hope someone is willing to answer these. 1).Why is it that if i define a global variable in a file, say main.c, and...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
0
by: Francois | last post by:
Hi, I think I found a bug with VS, and I've included a project example of the problem I got. I've got a project deep into a set of folders. The project have an additional include library...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
5
by: Tio | last post by:
I have project in MFC(vc++) . There are files and classes: classes:dialog1,dialog2,aaa,bbb ---------------------- main.cpp --------------------- #include "mainfrm.h" #include "dialog1.h"...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.