In drupal, how do I get the image url in my module folder?

Suppose I have a module mymodule. In mymodule forlder I have a folder with images, in this folder I have images img1.jpg, etc.

How to get the url of these images?

+5
source share
4 answers
drupal_get_path('module', $module_name);
+5
source

The easiest way, as mentioned above, is to use the relative path to the root of the site:

'/' . drupal_get_path('module', $module_name) . '/img1.jpg'

Using this without a trailing slash at the beginning will split it into several level aliases, for example. http://www.your_site.dev/category/2012/11/02/

+3
source
// path
drupal_get_path('module', $module_name) . '/images';

file_create_url (drupal_get_path ('module', $module_name)). '/'; >

0

To get the correct URL for your image, you need to add base_path()at the beginning of your image path. Valid URL:

$url = base_path() . drupal_get_path("module", "MY_MODULE") . "/image.png";

0
source

All Articles