473,659 Members | 3,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Image SRC

I would like to use an include for my header and navigation, and
because subsequent files may be in different directories, I want to
use a dynamic relative link for the images, sort of like:

<img src="<? $root ?>/images/foo.gif" />

I suppose the easiest thing to do is just use absolute links, but
is there a way to set this up so I can PHP instead?

TIA
Ian
--
http://www.bookstacks.org/
Jul 17 '05 #1
10 3223
Ian Rastall wrote:
I would like to use an include for my header and navigation, and
because subsequent files may be in different directories, I want to
use a dynamic relative link for the images, sort of like:

<img src="<? $root ?>/images/foo.gif" />

I suppose the easiest thing to do is just use absolute links, but
is there a way to set this up so I can PHP instead?

TIA
Ian

Hi Ian,

The question is this: How can PHP know which path (relative or absolute)
should be added?
If you can describe it clearly, you can program PHP to do it.
I am sure of that.

But you didn't provide us with any usefull information, so I am unsure what
kind of answer you expect.

As for the syntax: That is ok, as long as $root contains something that can
be parsed before the path.

Regards,
Erwin Moller
Jul 17 '05 #2
In comp.lang.php Erwin Moller wrote:
But you didn't provide us with any usefull information, so I
am unsure what kind of answer you expect.


Hi Erwin. I'll try and provide some better information. The
problem, essentially, is that I have a testing server set up, so
that the path to the main index file is
http://localhost/gongfamily/
but the URL when it gets on the remote server will be
http://www.gongfamily.net/

Now, my directory tree so far is very simple:

gongfamily
-----images
-----sundry
-----daevid
-----gilli
(and others at the same directory level)

The main index file has a PHP include in it, which points to
sundry/header.txt

In header.txt, I have a lot of image calls, in the form of:

src="images/foo.gif"

This works fine with the front page, but in the index page for
http://localhost/gongfamily/daevid/

the images are broken, because the links are relative. I could
make the links absolute, but then I couldn't use my testing
server. There might be an Apache solution to this, such as
setting up some sort of alias or virtual root, but that stuff is
beyond me.

I hope that helps. I'm tearing my hair out right now. :-)

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #3
Ian Rastall wrote:
In comp.lang.php Erwin Moller wrote:
But you didn't provide us with any usefull information, so I
am unsure what kind of answer you expect.


Hi Erwin. I'll try and provide some better information. The
problem, essentially, is that I have a testing server set up, so
that the path to the main index file is
http://localhost/gongfamily/
but the URL when it gets on the remote server will be
http://www.gongfamily.net/

Now, my directory tree so far is very simple:

gongfamily
-----images
-----sundry
-----daevid
-----gilli
(and others at the same directory level)

The main index file has a PHP include in it, which points to
sundry/header.txt

In header.txt, I have a lot of image calls, in the form of:

src="images/foo.gif"

This works fine with the front page, but in the index page for
http://localhost/gongfamily/daevid/

the images are broken, because the links are relative. I could
make the links absolute, but then I couldn't use my testing
server. There might be an Apache solution to this, such as
setting up some sort of alias or virtual root, but that stuff is
beyond me.

I hope that helps. I'm tearing my hair out right now. :-)

Ian

Aha, ok:

You could try several solutions.
However: in my humble opinion a 'relative path solution' for the images is
the best solution.
In that way you don't have to worry about changing location.

But you end up with 2 (or maybe more) versions of header.txt
header1.txt
<img src="/images/foo.gif">

header2.txt
<img src="../images/foo.gif">
If that is no problem, do it that way.

If you think that is messy, try this:
(I also use it to include functionsfiles and such)
I always have an includefile in all my scripts at top.

In that includefile I have 1 variable that contains the:
* full URL to root of your application.
(in the include:)
$myAppRoot = "http://localhost/gongfamily/";
Including that variable makes it easy to refer to the imagedirectorie s, no
matter from where you use them:
<img src="<?= $myAppRoot ?>/images/layout/version1/foo.gif">

If you switch your application to another location, you only have only to
change that variable.

Of course, you can also use $_SERVER to do the same. It contains all kind of
usefull information, like the path to the current script. But I prefer 1
simple variable to set this. Matter of taste.

Good luck.

Regards,
Erwin Moller
Jul 17 '05 #4
In comp.lang.php Erwin Moller wrote:
In that includefile I have 1 variable that contains the:
* full URL to root of your application.
(in the include:)
$myAppRoot = "http://localhost/gongfamily/";
Including that variable makes it easy to refer to the
imagedirectorie s, no matter from where you use them:
<img src="<?= $myAppRoot ?>/images/layout/version1/foo.gif">

If you switch your application to another location, you only
have only to change that variable.
Thank you! That's a good solution. Not entirely hands-off, but
very easy to modify.
Of course, you can also use $_SERVER to do the same. It
contains all kind of usefull information, like the path to the
current script.


If possible, could you give me the syntax for that? That sounds
like the totally hands-off solution. But if not, the first is
perfect.

As far as src="/images/foo.gif" I couldn't get that to work, at
least not locally.

Thanks again!

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #5
Erwin Moller wrote:

I wasn't very clear. Some modifications:

Aha, ok:

You could try several solutions.
However: in my humble opinion a 'relative path solution' for the images is
the best solution.
In that way you don't have to worry about changing location.

But you end up with 2 (or maybe more) versions of header.txt
header1.txt
<img src="/images/foo.gif">

header2.txt
<img src="../images/foo.gif">
If that is no problem, do it that way.

If you think that is messy, try this:
(I also use it to include functionsfiles and such)
In which case I have a var in the includefile like:
$fullPathToRoot = "/home/erwin/public_html/someapp"

And from a script:
include "myConffile.php ";
include "$fullPathToRoo t/include/somefunctions.p hp";

So the same principle, but not for a http:// but for a normal path.
I always have an includefile in all my scripts at top.

In that includefile I have 1 variable that contains the:
* full URL to root of your application.
(in the include:)
$myAppRoot = "http://localhost/gongfamily/";
Including that variable makes it easy to refer to the imagedirectorie s, no
matter from where you use them:
<img src="<?= $myAppRoot ?>/images/layout/version1/foo.gif">

If you switch your application to another location, you only have only to
change that variable.

Of course, you can also use $_SERVER to do the same. It contains all kind
of usefull information, like the path to the current script. But I prefer
1 simple variable to set this. Matter of taste.
Try:

<pre>
<? var_dump($_SERV ER); ?>
</pre>

to see the content.

check: http://nl2.php.net/reserved.variables

Good luck.

Regards,
Erwin Moller


Jul 17 '05 #6
> This works fine with the front page, but in the index page for
http://localhost/gongfamily/daevid/

the images are broken, because the links are relative. I could
make the links absolute, but then I couldn't use my testing
server. There might be an Apache solution to this, such as
setting up some sort of alias or virtual root, but that stuff is
beyond me.


My current project lives in a directory called 'dp', and my test machine is
called 'monkey' (or 'localhost'). I use this function to set a couple of
path variables:

function setPaths( &$filePath, &$httpPath )
{
if( (strcmp( $_SERVER['SERVER_NAME'], "monkey" ) == 0) ||
(strcmp( $_SERVER['SERVER_NAME'], "localhost" ) == 0) ) {
$filePath = "/home/derek/public_html/dp/";
$httpPath = "/~derek/dp/";
} else {
$filePath = "/home/derek/html/www.dp.com/public_html/";
$httpPath = "/";
}
}

This gets called at the top of each page as part of the standard boilerplate
code I always use. I then access images and the like with $httpPath and
text and config files with $filePath.

--
The email address used to post is a spam pit. Contact me at
http://www.derekfountain.org : <a
href="http://www.derekfounta in.org/">Derek Fountain</a>
Jul 17 '05 #7
In comp.lang.php Erwin Moller wrote:
In that includefile I have 1 variable that contains the:
* full URL to root of your application.
(in the include:)
$myAppRoot = "http://localhost/gongfamily/";
Including that variable makes it easy to refer to the
imagedirectorie s, no matter from where you use them:
<img src="<?= $myAppRoot ?>/images/layout/version1/foo.gif">


Well, I'm running into problems. I have at the top of each of my
two (so far) index files:

<?php $myAppRoot = "http://localhost/gongfamily/"; ?>

Then for my include, I write:

<?php
include('$myApp Root."/sundry/header.txt"');
?>

But it doesn't recognize it. I'm not sure if it's working with
the images, either, as when I look at the source code for the
main index file, the images show up as src="images/foo.gif"
instead of as src="http://localhost/gongfamily/images/foo.gif".

I'm sure this is a simple problem that a real PHP hacker would
understand, but I'm befuddled.

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #8
Ian Rastall wrote:
In comp.lang.php Erwin Moller wrote:
In that includefile I have 1 variable that contains the:
* full URL to root of your application.
(in the include:)
$myAppRoot = "http://localhost/gongfamily/";
Including that variable makes it easy to refer to the
imagedirectorie s, no matter from where you use them:
<img src="<?= $myAppRoot ?>/images/layout/version1/foo.gif">
Well, I'm running into problems. I have at the top of each of my
two (so far) index files:

<?php $myAppRoot = "http://localhost/gongfamily/"; ?>

Then for my include, I write:

<?php
include('$myApp Root."/sundry/header.txt"');
?>


which is wrong indeed. :P
You include a file on your LOCAL FILESYSTEM, not via http.

Two advises:
1) Do not put
<?php $myAppRoot = "http://localhost/gongfamily/"; ?>
above every script.
Make THAT an includefile, so you have to change this ONLY on one location
when you have 100 files.

2) Make 2 variables in that includescript:
a) One for your local path to your app
eg
$MyLocalRoot = "/home/ian/public_html/myapp/";

b) One for http-requests:
$myLocalHttpRoo t = "http://www.yoursite.co m/";
You mixed them us, and in your example you try to include an includefile
(php) via http.

Hope that helps.

Also, read the response of Derek too in this thread. :-)

Regards,
Erwin Moller


But it doesn't recognize it. I'm not sure if it's working with
the images, either, as when I look at the source code for the
main index file, the images show up as src="images/foo.gif"
instead of as src="http://localhost/gongfamily/images/foo.gif".

I'm sure this is a simple problem that a real PHP hacker would
understand, but I'm befuddled.

Ian


Jul 17 '05 #9
In comp.lang.php Erwin Moller wrote:
2) Make 2 variables in that includescript:
a) One for your local path to your app
eg
$MyLocalRoot = "/home/ian/public_html/myapp/";

b) One for http-requests:
$myLocalHttpRoo t = "http://www.yoursite.co m/";
You mixed them us, and in your example you try to include an
includefile (php) via http.


Thanks, Erwin. I appreciate the help.

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #10

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

Similar topics

2
13442
by: Sam | last post by:
Hello everyone, I have a table, which contains a picture column, I put URL info into it. "www.myweb.com/1.jpg..." I want to show this picture in my crystal report, I find some samples show the "static" picture in Crystal report, No "Dynamic" one. Can Crystal Report do that? Thanks in advance. Sam
0
1507
by: Michael Huhn | last post by:
I have a web page default.aspx and a dynamic image image.aspx. Image gets parameters via querystring and outputs a gif. Using JavaScript I reload the image with changed parameters quite often. Sometimes it happens that the image does not appear (red cross instead) or that ie keeps loading for minutes. Opening that image in another browser gives me a "403.9: too many connections". Does iis create a new connection on every reload of that...
5
4389
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK' print 'Content-type: text/html' print print '<HTML><HEAD><TITLE>Python Dynamic Image Creation Test</TITLE></HEAD>'
3
2710
by: JOSEPHINE ALVAREZ | last post by:
I have this code that I want to use to do a rollover. However, because the company I am doing it for is continually changing the text, I want to be able to use dynamic text to change the text on the fly, and still have the rollover work. I have taken the text off of the buttons, but cannot figure out how to do it with dynamic text using javascript and html. For example, in the columns of this row, I want to put "About...
0
2775
by: UtilityWarrior | last post by:
If you use Visual Basic 6 or VB.net and want to create PDFs from images royalty free then this DLL is for you. The Image to PDF Dynamic Link Library (DLL) will convert one or more images (JPEG, TIFF, PNG, GIF, BMP, PCX and TGA) into a PDF document. Supports multi-image TIFFs and animated GIFs. You can add clickable image stamps (eg company logo to web site), passwords, bookmarks and can even create simple full screen PDF slideshows -...
11
3040
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
9
2948
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I got the core of the javascript from here: http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm I noticed in the demo that sometimes the content takes a long
7
2368
by: dino d. | last post by:
Hi- I want to create a dynamic image with areas so that when the user clicks different areas, the user jumps to those pages. The problem is, I can't seem to figure out how to do this efficiently. Suppose I have a table,items in a database: itemid description count So, basically, I want to create an image that has 3 ovals, representing the top 3 occurring items (with the highest count) in
1
4651
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3492
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
0
8428
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
8748
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8628
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...
0
7359
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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.