Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the URL of an image inside a module directory?

In the directory containing a custom module, I have a directory containing images.

How do I get the URL of those images?

like image 296
Vasil Avatar asked Jan 08 '11 19:01

Vasil


2 Answers

drupal_get_path('module', $module_name);
like image 73
Ted Avatar answered Sep 28 '22 08:09

Ted


The easiest way, like referred above, is to use the relative path to site root:

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

Using it without the trailing slash in the beginning would break it on multiple level aliases, e.g. http://www.your_site.dev/category/2012/11/02/

like image 25
Ain Tohvri Avatar answered Sep 28 '22 07:09

Ain Tohvri