473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Problem in including any file in html while hosting

Hi all,

First of all, I use linux (fedora 6) and apache to host
I have a problem of including any file in html while hosting only
Even a simple code like

[HTML]<img src="/home/user/abc.jpg" />[/HTML]
won't show the included image.

To make it more clear,
If I view same page just opening it (not hosting) like
file:///home/user/abc.html
It shows the image included.

But if I view the webpage using
http://localhost/abc.html
Then it won't show any images

I need to host the page, show how shall I include the image.
Actually, its not just problem with images only, but every type of file.

Thanks
Jan 5 '08 #1
9 1870
numberwhun
3,509 Expert Mod 2GB
Hi all,

First of all, I use linux (fedora 6) and apache to host
I have a problem of including any file in html while hosting only
Even a simple code like

[HTML]<img src="/home/user/abc.jpg" />[/HTML]
won't show the included image.

To make it more clear,
If I view same page just opening it (not hosting) like
file:///home/user/abc.html
It shows the image included.

But if I view the webpage using
http://localhost/abc.html
Then it won't show any images

I need to host the page, show how shall I include the image.
Actually, its not just problem with images only, but every type of file.

Thanks
Ok, so it works on your local machine but not the hosting machine. Stupid question, but when you uploaded the html page, did you also happen to upload the image(s) as well? If you don't, how will the html page know where to find them?

You would also have to change the path to wherever you put the images on the hosting server.

Also, no need to put your localhost URL in your threads. We can't view something that is local to your machine.

Regards,

Jeff
Jan 5 '08 #2
Ok, so it works on your local machine but not the hosting machine. Stupid question, but when you uploaded the html page, did you also happen to upload the image(s) as well? If you don't, how will the html page know where to find them?

Thanks for replying. But, yeah, your question was somewhat stupid.
Let me explain my problem.

I'm using apache to host (locally) in my own PC (using fedora 6).

I have a html file which includes an image. (plz remember I'm fully aware that I should give complete path of the image and I have done that)

Now I can open this file in 2 ways.
1. Just double click this file to view it in some browser (firefox in my case).
2. OR put this file into the /var/www/html folder (which is default directory to host a website, as it is htdocs in windows) and view this file as htttp://localhost/filename.html in a browser.

Case 1 works very fine.
Case 2 is giving problem. Even I give full path to the image, it isn't showing the image. Only those images which are in same directory or sub-directories are being shown. I can't include anything outside this /var/www/html directory


I have only one PC and I'm testing in it and not hosting from any other server.
Help me solve this problem.
Thanks
Jan 6 '08 #3
garrow
32
Your absolute URLS need to reference the web visible path, rather than the filesystem path

In your example you pointed images to
Expand|Select|Wrap|Line Numbers
  1. /home/user/abc.jpg
On your filesystem these images exist, but the web brower tries to access that location it is looking for
Expand|Select|Wrap|Line Numbers
  1. localhost/home/user/abc.jpg
which the server translates to
Expand|Select|Wrap|Line Numbers
  1. /var/www/html/home/user/abc.jpg
Which doesn't exist.

So while absolute paths are correct, they must be absolute to the server, not the filesystem.

I hope this helps.

You hit the nail on the head with this comment
I can't include anything outside this /var/www/html directory
Thats right you cant.
To do so you would need to make that directory readable by the webserver, and either direct it as a subdir of localhost or create a virtualhost for just that directory.

The only other option you have is to use a server side language such as PHP and fopen() the file on the server and parse it out.
The PHP file would still need to be somewhere under the webroot location though.
Jan 7 '08 #4
garrow
32
also you dont NEED to use absolute URLs, relative ones are fine.
Jan 7 '08 #5
Hey,
Thanks for clearing most of my doubts.
But stll I have a doubt.


You hit the nail on the head with this comment
I can't include anything outside this /var/www/html directory
Thats right you cant.
To do so you would need to make that directory readable by the webserver, and either direct it as a subdir of localhost or create a virtualhost for just that directory.
I have created a directory /usr/tmp/uploads
/usr has read and execute permissions for all
tmp has read, write and execute permissions for owner, group and others all.
and I have given read, write, and execute permission to the uploads directory as well.

Even then it's not showing the image.

Thanks
Jan 10 '08 #6
garrow
32
for security, most webservers are configured not to access files that are outside of the documentroot.
therefore a web served file CANT access resources that are outside of the document root.

eg
root
/
documentroot
/var/www/html/

so if a file tries to access
[HTML]href="/"[/HTML]
it gets
/var/www/html/
not
/

this means there is no way to access
/var/
or /usr/
unless you configure the webserver documentroot to be something else. ( not recommended.)

In apache you can create multiple vhosts that have different documentroots, but then they will be different hosts eg
site1.local and site2.local and would be referenced like
site1.local/index.html
etc

On second thought, the best alternative is to create symlinks to files
for example

/var/www/html/lib/
could be a symlink to
/usr/lib/myframework/lib/

This way you could install one copy of your chosen resource, and have it available at both locations.
also means you could have

/var/www/html/application1/lib/
/var/www/html/application2/lib/
/var/www/html/application3/lib/

all being symlinks to
/usr/lib/myframework/lib/

this way the files are stored outside you webroot, but are available from relative paths WITHIN the webroot.

Hope that clears that up a bit.
Jan 12 '08 #7
garrow
32
In your
/usr/tmp/uploads
example.

2 options.
You could move that folder into
/var/www/html/uploads/

Or
create a symlink from
/var/www/html/uploads/
to
/usr/tmp/uploads

That should work.

I dont know where my brain was last week. :D
Jan 12 '08 #8
Thanks Garrow for the solution.
I am now convinced that I can't get outside of /var/www/html (except using symlinks).
Jan 13 '08 #9
garrow
32
wait let me just reiterate that
you cant access files outside the webroot :D
Jan 14 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ray | last post by:
Hi I need to access an access db via php. My hosting provider is using php version 4.3.10 on a windows 2003 platform. I think that php was installed with the Plesk for windows package/control...
2
by: TrashOverride | last post by:
Hello guys i have a question about apache... i have installed Apache 2.0.54 PHP 5 MySQL 4.01 and i was wondering if i could use a name to access my apache server -> not to use http://localhost but...
2
by: Bruce W...1 | last post by:
I created an RSS aggregating website based on this article: http://msdn.microsoft.com/asp.net/using/understanding/XML/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-createrssw-aspnet.asp The...
10
by: Don Munroe | last post by:
This one has me stumped. I have three web applications running on two different servers. The first that works fine is hosted by a .Net hosting company. Everyone that uses it has no problems...
4
by: Trond Meistad | last post by:
I have a website where I run a simple asp.net web application. On Sunday night, requests to this webapplication started to time out. After much debuggeing with no result, I created a new...
3
by: Will Chamberlain | last post by:
For the next couple of months I am hosting 2 domains with one host (Brinkster). What I have done is setup a page called default.aspx and a select case for SiteNameURL = ...
20
by: Shanta McBain | last post by:
Hi I am running Mandrake 10 and would like to get sql-ledger to access the database. I can get in to the database with a local user at the command prompt and Web Admin. sql-ledger returns...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...

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.