Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am new to Ubuntu and i wanted to write a website on it. I am used to Windows XP and i am used to writing the display image code as follows:

img src="C:\Users\Username\My Pictures\Test.jpg" alt="Picture"

In ubuntu they do not have drive letters, what should i do? My picture is in a seperate partition named documents and under the file properties it says the directory is:

/media/Documents/Files/Micah/Homepage Website/Picture.jpg

However when i write it into html it just displays picture in normal text!!! any help? (i hope there is cuz thats wut this site is for :P lol)

share|improve this question

5 Answers 5

So did you try < img src="/media/Documents/Files/Micah/Homepage Website/Picture.jpg"> ?

share|improve this answer

Permissions might hinder you. The entire path to the image must be readable by the Web server. If you are using Apache running as the www-data user, then your directories should probably be set to 0755 (drwxr-xr-x), and the files, 0644 (-rw-r--r--). You can see the permissions in a console/shell with something like this:

cd /media
ls -l

You can change permissions with something like this:

sudo chmod 0755 directory_name
sudo chmod 0644 file_name

Do that for each directory and all the files you want to access. Or, in two swipes, one for directories, one for files, get them all without picking though each dir/file:

sudo find /media -type d -exec chmod 0755 {} \;
sudo find /media -type f -exec chmod 0644 {} \;

When you know the permissions are correct, you would benefit by creating a symbolic link to the directory instead of trying to reference them all by absolute file system path. Change directories to the website document root. Let's say this is /home/micah/public_html/.

cd /home/micah/public_html/
ln -s /media/Documents/Files/Micah/Homepage\ Website/ images

Now you have a symbolic link, like a virtual directory, to the location of the images. In order for this to work, Apache needs to know that it is allowed to follow the sybmolic link. So, in your Apache config file, where you have defined your website, look in the 'Directory' directive to make sure you have specified the "FollowSymLinks" option.

<Directory />
    Options FollowSymLinks
</Directory>

Restart the Web server after this.

sudo service apache2 restart

Then, the XHTML is this:

<img src="/images/Picture.jpg" width="" height="" alt="" title="" />

By the way, when you have spaces in a URI, and for each blank space, substitute the HTML character entity, %20.

If you are just creating HTML files, ignore the Apache part.

share|improve this answer
    
I don't think he's using Apache, he seems to be creating a purely-local webpage. Still your answer is very useful if Apache is involved! –  roadmr Dec 6 '11 at 15:56
    
@roadmr purely local still needs a web server :) hee hee –  user8290 Dec 6 '11 at 15:58
    
@roadmr oh! goodness... single html files ... gotcha! yeah, you may be right! –  user8290 Dec 6 '11 at 16:10

As I see in your code, your picture has a space in one of its folders: /Homepage Website/Picture.jpg

Usually, that's not a good idea. Try putting an underscore:

/Homepage_Website/Picture

It's also a good practice to put filenames in lowerscore: "picture" instead of "Picture".

That can turn into problems sometimes.

share|improve this answer

Although you are using Ubuntu this is more properly a HTML question. Remember, the web browser will look first in the folder that the file is in that it is opening. So, if your opening page is index.html (web browsers look for that name as standard) and the image is in the same folder, then the brower will load Picture.jpg with the width and height set for it.

Such has

<img src="Picture.jpg" width="1000px" height="200px">

I use this method to set a background image to a kind of ebook that I am creating for my personal use where I use a web browser to access the documents.

You can use "../filename" to get to a file in the previous folder. I use that to return to the previous page and to reference the CSS stylesheet that is being used. You need that reference in every document.

<link rel="stylesheet" type="text/css" href="../stylesheetname.css" />

if the stylesheet is one folder backwards.

I am trying to find an example from my work of referencing a file in another folder so that you can put all your images in a Images folder. But it is awhile that I did any work on this project. I will give you this for now.

Edit: It seems that you simply do this:

<img src="/images/Picture.jpg" width="1000px" height="200px">

Or this:

<img src="/images/moreimages/Picture.jpg" width="1000px" height="200px">

You might find this W3Schools for HTML tutorials useful

Regards.

share|improve this answer

You need to give permission to that folder from which you are accessing the img. open you terminal and type this code:

sudo chmod -R 777 /media/Documents/Files/Micah/Homepage Website/Picture.jpg 

After that press enter

and this is img tag

<img src="C:\Users\Username\My Pictures\Test.jpg" alt="Picture">

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.