Re: Can't display images

Giganews Newsgroups
Subject: Re: Can't display images
Posted by:  Mark Goodge (usen…@listmail.good-stuff.co.uk)
Date: Thu, 21 Jan 2010

On Thu, 21 Jan 2010 12:32:34 -0800 (PST), dushkin put finger to
keyboard and typed:

>Hi All,
>
> I am preety new to web development.
> I must be missing something very basic here.
>
> I developed a php file named Register.php.
> I put couple of images in it.
> I use apache tomcat 6.0
>
> I loaded the file by typing http://localhost:8080/forphp/Register.php
>on the address bar  in IE8.
>
> The images are not loaded.
>
> The images properties shows that they refer to http://localhost:8080/<image
>file name> as the image is at the same folder like Register.php

There's your problem, then. You've given the images an absolute
instead of relative path, and they're being loaded (or, rather,
failing to load) from the root directory.

Your HTML source looks something like this:

<img src="/image.jpg">

whereas it should look like this:

<img src="image.jpg">

or this:

<img src="/forphp/image.jpg">

The first of those (note the absence of the leading /) makes the image
location relative to the file calling it rather than the root
directory, while the second uses an absolute path (with a leading /)
and includes the directory where the images are located.

Mark

--
Blog:http://mark.goodge.co.uk
Stuff:http://www.good-stuff.co.uk

Replies

In response to

Can't display images posted by dushkin on Thu, 21 Jan 2010