Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 13th, 2012, 06:06 AM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
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
Reply With Quote
  #2 (permalink)  
Old February 13th, 2012, 06:10 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
  #3 (permalink)  
Old February 13th, 2012, 06:24 AM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
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..
Reply With Quote
  #4 (permalink)  
Old February 13th, 2012, 06:46 AM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
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
Reply With Quote
  #5 (permalink)  
Old February 13th, 2012, 06:53 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
  #6 (permalink)  
Old February 13th, 2012, 08:17 AM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
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..
Reply With Quote
  #7 (permalink)  
Old February 13th, 2012, 08:43 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:29 AM.


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