Community Documentation

Adding content with images - basic

Last updated September 19, 2007. Created by sepeck on September 19, 2007.
Log in to edit this page.

With Drupal you can add images to your content. How it is
displayed still depends on the theme you are using and the CSS included
handles the IMG tag.

  1. Enable upload module
  2. Set your role as allowed to upload files
  3. Check your space and attachment settings administer > site configuration > file uploads
  4. Enable your content type for uploads
  5. Create content
  6. Attach file - uncheck List file, copy the file path under the box once it's uploaded.

    Now you can use <img src="path/image.png" /> in the content area.

    Note

    Assumes your filter allows the use of <img>

Comments

Expanding on point (6)

Expanding on point (6)

Image paths in the content

When you copy the path of the uploaded file into the content to place the image, the correct way to specify "img src=" depends on your site's setup. Assuming that "filepath" is your Drupal images directory:

a) If you are using Clean URLs, then specify an absolute domain-independent path:
- When a site is accessed as http://example.com then use "/filepath/image.png".
- When a site is accessed as http://example.com/drupalsite then use "/drupalsite/filepath/image.png".

b) If you are not using Clean URLs, then (a) is still OK, but you have a simpler alternative: You can always specify only a relative path, for example "filepath/image.png" (without a front slash), no matter whether the site is accessed as a subdirectory or not.

Obviously a fully qualified URL for an image ("http://example.com/filepath/image.png") will always work as long as your site's domain remains the same.

Note: When switching between "Clean URLs" and "no Clean URLs" or when changing a site's URL path, image links may break if you don't take into account these differences.

There wasn't anything about

There wasn't anything about filters before this statement "Assumes your filter allows the use of Only local images are allowed.".
I have been looking for a place to edit my filter since when I tried to insert image, the picture didn't show.

If it is a filter problem,

If it is a filter problem, you could create your content using the Full HTML input format, but if you let other users use it there are security concerns.

Or, you can go to the admin/settings/filters page and "configure" the Filtered HTML input format. Among other filters, it has enabled the "HTML filter". Go to the "Configure" tab, and you can add <img> to its allowed HTML tags.

can`t open image

Hi,

i just want to insert an image into a Content of type Story.
I did it like it is documented:

1.Enable upload module
2.Set your role as allowed to upload files
3.Check your space and attachment settings administer > site configuration > file uploads
4.Enable your content type for uploads
5.Create content
6.Attach file - uncheck List file, copy the file path under the box once it's uploaded.

Thats image Link in the Body Input Field:
http://localhost/cms/sites/default/files/af74ebcede_0.jpg

When i view the page. I see nothing.
When i copy the Image Link into the Browser, i get the message:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, you@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
ErrorLog Message:
[Fri Dec 04 13:23:29 2009] [alert] [client ::1] /Applications/xampp/xamppfiles/htdocs/cms/sites/default/files/.htaccess: SetHandler not allowed here, referer: http://localhost/cms/?q=node/1

I have set the permissions for the file folder to 775.

What is wronng? What can i do?

Thanks.

cheez

The file mentioned in the

The file mentioned in the error log, "tdocs/cms/sites/default/files/.htaccess", is a file created automatically by Drupal to make the uploads directories somehow more secure. It contains the line SetHandler some-nonsense to prevent user-uploaded php scripts from running.

However, your server configuration may not allow SetHandler directives or even Options directives in .htaccess files, so you may need to edit the .htaccess file, remove those lines, and then write-protect the file.

Anyway, that SetHandler directive is not necessary if you set up file uploads in Drupal to allow only certain types of files (images, documents etc but not php files). But beware of allowing FTP uploads.

-

For those who DO have access to the server, I think the proper way is to edit the apache conf file adding into your VirtualHost tag the following...

<Directory /home/www/yoursite/html/sites/default/files>
AllowOverride all
</Directory>

don't forget to change the path ;-)

Extra Garbage in Copied Image URL

After I upload the image file, I copy it from under the File Attachments - Description and paste it into the body of my page. But extra non printing characters are added to the beginning and to the end of the copied image URL. Then the image fails to display. So each time I paste an image URL, I have to backspace and delete the blank characters in the front and end of the URL to get it to display.
Example: Only local images are allowed. [beginning script]
URL under File Attachments Description: http://example.org/sites/default/files/picture122.gif
When I paste the clipboard in between the two quote marks I get:
Only local images are allowed.http://example.org/sites/default/files/picture122.gif ">
Can anyone shed any light on this?

An Old Boy Scout Volunteer