0

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.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Menon Jats
  • 317
  • 3
  • 14

2 Answers2

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
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