473,799 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stupid PHP includes question.

Ben
This is probably a very simple question (I hope), but my usually great
web searching abilities have not turned up the answer I am looking for.

I have a php page that includes a file for example index.php has an
include for menu.htm. Inside menu.htm are some images in the same
directory. All works great in that scenario.

Here's where the trouble begins. If I want to include menu.htm inside
a php file that is in another directory (say testdir/page.php) it is
unable to load the images because it is assuming the images are in the
same directory as page.php... it does not know the images are in the
directory above (the same directory that menu.php is in).

So when including a file that is contained within another directory,
the including page (testdir/page.php) uses the currenty directory as
the starting point when evaluating relative paths... because of this
it's looking for the images in the same directory that it's in..
instead of in the above directory like menu.htm indicates. Not sure if
that makes sense... here is an example of the pages / directories.

for example:

c:\php\index.ph p
c:\php\menu.htm
c:\php\menuimag e.jpg
c:\php\testdir\ page.php

=============== ===============
code for index.php [WORKS]:
=============== ===============
<? include ("menu.htm") ?>
=============== ===============

=============== ===============
code for page.php [Does not work. cannot load images]:
=============== ===============
<? include ("../menu.htm") ?>
=============== ===============

/\
|
|
\/

even though menu.htm is in the same directory as the .jpg file it is
looking for the .jpg in the directory it's being called from
(testdir)... the same directory that the including page (page.php) is
in.

Hope this makes sense. Is there a php function that can correc this
easily or am I using the include wrong? I have been able to correct
this by writing code that checks the URL and changes the reletive path
depending on which dir the including page is in... but that seems way
to complicated for this issue. I know there must be a simpler way.

Jul 17 '05 #1
4 1275
*** Ben escribió/wrote (20 Feb 2005 05:56:30 -0800):
So when including a file that is contained within another directory,
the including page (testdir/page.php) uses the currenty directory as
the starting point when evaluating relative paths... because of this
it's looking for the images in the same directory that it's in..
instead of in the above directory like menu.htm indicates. Not sure if
that makes sense... here is an example of the pages / directories.


It's easier than you think. Including a file is exactly the same as opening
it in an editor, copying it to clipboard and pasting in your current
script.

If you want to use relative paths, they must be relative to the document
where you are pasting the text. If you're planning to paste it in documents
located if different directories, then you must use absolute paths.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox
--
Jul 17 '05 #2
> for example:

c:\php\index.ph p
c:\php\menu.htm
c:\php\menuimag e.jpg
c:\php\testdir\ page.php

=============== ===============
code for index.php [WORKS]:
=============== ===============
<? include ("menu.htm") ?>
=============== ===============

=============== ===============
code for page.php [Does not work. cannot load images]:
=============== ===============
<? include ("../menu.htm") ?>
=============== ===============

/\
|
|
\/

even though menu.htm is in the same directory as the .jpg file it is
looking for the .jpg in the directory it's being called from
(testdir)... the same directory that the including page (page.php) is
in.

Hope this makes sense. Is there a php function that can correc this
easily or am I using the include wrong? I have been able to correct
this by writing code that checks the URL and changes the reletive path
depending on which dir the including page is in... but that seems way
to complicated for this issue. I know there must be a simpler way.


I don't know any (antive) function that would do it for you...
Moreover I think it's a good thing to put some var in path..
The way I use is to define all my directory as constant in first
included file, so, I can modify this declaration if I change any path..
(it could include changing entry page, even if I dislike this)
After this, You just have to use this constant.. : <img
src="<?=IMAGEDI R;?>myimage.ext "> which would take care of relative path

sorry for my poor english
Jul 17 '05 #3
Ben
Doh, I was afraid I would have to use absolute paths. I thought I came
across a function once that will get you the absolute path of a file...
but even if that existed I would still be stuck if using that function
inside the include file when calling it from another directory.

Jul 17 '05 #4
I noticed that Message-ID:
<11************ **********@l41g 2000cwc.googleg roups.com> from Ben
contained the following:
Doh, I was afraid I would have to use absolute paths.


Why is this a problem?
<img src="/images/image.jpg">

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5

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

Similar topics

2
1611
by: Joe Mowry | last post by:
First off, I'm posting this question for a friend that doesn't have access to the news groups. Problem: Using PHP as the base and has several PHP < includes > for various functions, all this by its self works just fine. Failure occurs on adding the XML include. Here's the wierd: If all the PHP includes are removed/commented out,
119
4640
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see, http://www.alistapart.com/articles/betterliving/ I read on http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dnnetdep/html/netfxcompat.asp It said they changed stuff like this
12
2996
by: tshad | last post by:
I am not sure why I am getting this error: I have the following code I want to run from another include file that holds all my functions. functions.inc ************************************************************************************ <Script runat="Server"> Sub fnHeader(client As String) response.write("<!-- #include file = ../includes/staffingHeaders.inc -->")
2
1294
by: Ron Weldy | last post by:
I read that you don't need .cs files to deploy but I suppose if you are trying to reconstruct someone's work, you will need these files. Is that correct?
6
1618
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no stupid question. Is that another for political correctness I am attempting an install of 7.4.3 on FreeBSD O/S 4.9, apparently remnants of 7.3.x are scattered around on the disk from (a) previous ports installation, causing mutex_lock/unlock,...
1
1242
by: antjudy01 | last post by:
Hi, I was thinking about joining the MSFT Empower program which includes "5 licenses to Visual Studio 2005 Professional Edition". My question is how do I get the media to actually install the Visual Studo product? The Empower program comes with all sorts of licenses to different products, but I don't understand how I get the media to actually install the programs...
3
2539
by: Jeff | last post by:
I have an asp page. Now I know this is sortof OT, but I am not sure of the forum to get an answer. I have an include on this asp page <!-- #include file=\forum\includes\consts-inc.asp --> now, it gives me this error: File attribute '\forum\includes\consts-inc.asp' cannot start with forward slash or back slash.
6
1531
by: Malvolio | last post by:
I know this is a *really* stupid question but what the hell is visual c++? I downloaded it and it doesn't seem to work. It isn't like any c++ compiler I ever saw before and the manual on the Microsoft website did not improve my comprehension of it at all. How do you compile your source code with this thing? Is it a compiler at all? Am I crazy? I know it would probably take too much time to answer my dumb questions here but if you can...
2
1523
by: Lynx101 | last post by:
Hi, Is this a stupid question? Senario: Two tables linked together with an ID number. Question: When using a combo box, which refences another table by indexed autonumber, is there a way to copy the returned text value to a text field. I have many combo boxes and after the value changes I would like a normal text field to show the returned text value, regardless of which combo box was changed.
0
9686
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7564
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.