I'm beginner in drupal. I would like to fetch images from specific folder in drupal. Is there any way to fetch drupal images directly from any specific in custom theme.
Asked
Active
Viewed 612 times
0
-
I mean get the path of an image URL – Menon Jats Oct 08 '15 at 07:37
2 Answers
0
You should use only images from your theme. And you can get path to your theme like this:
$theme = drupal_get_path('theme',$GLOBALS['theme']);
Put that i.e. at top of template file that uses theme images. And then inside your theme templates you can have something like:
<img src="/<?php echo $theme; ?>/images/my_image.png">
If you stored you theme images inside images
dir...

MilanG
- 6,994
- 2
- 35
- 64
-
or at least I need that how to load module module function in custom theme – Menon Jats Oct 08 '15 at 09:33
0
If an array of image paths on your local filesystem is what you want - use this code, it should do what you need. gets all the png jpg gif paths within the sites/default/files/vegas
directory.
//We will use the stream wrapper to access your files directory
if ($wrapper = file_stream_wrapper_get_instance_by_uri('public://')) {
//Now we can easily get an actual path to that folder
$directory = $wrapper->realpath();
//Don't forget to append your "vegas" subfolder here
$directory .= DIRECTORY_SEPARATOR . 'vegas' . DIRECTORY_SEPARATOR;
$images = glob($directory . "*.{jpg,png,gif}", GLOB_BRACE);
foreach($images as $imagePath)
{
//Do your thing!
echo $imagePath;
}
}

Stas Parshin
- 1,458
- 1
- 16
- 21