Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2012, 06:06 AM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rookie question #2: How to reference the localhost folders

Hi,

I am in the development stage, so I dont't have an "actual" website URL. And I want to reference a file in the localhost folder structure, such as in

Code:
<img src="localhost/images/Logo.png" />
I looked on w3schools, but I didn't find anything helpful (not badmouthing w3schools !).

And,

when I'll finally move the pages to the real website, will I have to change all such references ? That'd be beastly !

Thanks,

Mike
 
Old February 13th, 2012, 06:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You can use relative links, which would work locally and when deployed to a server. Let's say your site / pages are located at C:\Site.

Inside this folder, create an HTML file and a sub folder called Images. You can now refer to the images in the sub folder from the HTML file in C:\Site like this:

<img src="Images/Whatever.gif" />

If you create another folder such as About and create a new HTML file in there, you can refer to the Images folder from that new HTML file like this:

<img src="../Images/Whatever.gif" />

../ goes "up" one level (e.g. from C:\Site\About into C:\Site) and then into the Images folder again.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 13th, 2012, 06:24 AM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry Imar,

I guess you explained it quite clearly, but I feel I should elaborate:

My server is ubuntu linux.

The localhost is actually located at /var/www/Website/htdocs. From this directory down begins my site folder structure (localhost/images, localhost/stylesheets etc.)

In localhost is the index.php page which is now my main page.

So how would I refer to image Whatever.png located in localhost/images/ from index.php ?

I got the rest of your explanation with ../images etc. :-)

Thanks for the patience,

Mike

Last edited by mike123abc; February 13th, 2012 at 06:28 AM..
 
Old February 13th, 2012, 06:46 AM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok,

so I tried to use

Code:
<img src="images/Logo.png" />
which I think you actually told me to do. It doesn't work, either.

Help !

Mike

Last edited by mike123abc; February 13th, 2012 at 06:50 AM.. Reason: zzz
 
Old February 13th, 2012, 06:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Linux is case sensitive, so make sure the folder and file names match exactly with your code.

Other than that, I don't see why this doesn't work if locahost is a folder with your HTML / PHP file and a sub folde called images.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 13th, 2012, 08:17 AM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had made a stupid mistake:

Code:
<td>img src=...</td>

vs.

<td><img src=... /></td>
No wonder it kept appearing like text !

Mike

PS. And it works both with "src=/images/..." and "src=images/...". Good to know ! I prefer "http://p2p.wrox.com/images/..." though, it makes more sense.

Last edited by mike123abc; February 13th, 2012 at 08:21 AM..
 
Old February 13th, 2012, 08:43 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, /images and images work from a file in the root. /images still works from a file at /whatever/something.html as it still points to the root. Using just images makes it easier to move the html and the images folder to a different location in your site.

Using the full domain also works but makes it extremely hard to rename the domain or reuse your content elsewhere

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rookie question: center webpage on screen mike123abc HTML Code Clinic 2 February 13th, 2012 05:41 AM
Rookie question mitch54 HTML Code Clinic 3 April 7th, 2010 01:18 PM
the rookie is back with a question mitch54 HTML Code Clinic 10 April 5th, 2010 09:23 AM
Small rookie question maximus101 VB Databases Basics 1 February 23rd, 2006 11:51 PM
Rookie question: container div not containing CFGerry BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 6 September 1st, 2005 09:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.