2011-01-08 50 views

回答

5
drupal_get_path('module', $module_name); 
0
// path 
drupal_get_path('module', $module_name) . '/images'; 

file_create_url(drupal_get_path( '模塊',$ MODULE_NAME))。 '/圖片';

+0

錯誤。 `file_create_url`將始終與_default/files_相關,而不是模塊目錄,因此URL最終將會像http://www.your_site.dev/sites/default/files/sites/all/modules/your_module/images這樣是不正確的。 – 2012-12-25 13:42:12

+0

是的,正確的。 `file_code_url`將返回/ sites/default/files下的URL。謝謝。 – 2014-03-12 20:14:45

3

最簡單的方法,如上面提及,是使用相對路徑來站點根:

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

使用它而不在開始最後的斜線將打破它在多個級別別名,例如http://www.your_site.dev/category/2012/11/02/

0

要獲得圖像的正確URL,您需要在圖像路徑的開頭追加base_path()。正確的URL將是:

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

相關問題