Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1005465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:18:00+00:00 2026-05-16T08:18:00+00:00

I have some images in drupal/sites/default/files/images/. How can I get the absolute path for

  • 0

I have some images in drupal/sites/default/files/images/.

How can I get the absolute path for an image like abc.jpg placed in this directory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:18:01+00:00Added an answer on May 16, 2026 at 8:18 am

    If Drupal is on its own domain (i.e., http://example.com), the absolute path would be /sites/default/files/images/abc.jpg.

    If Drupal is in a subfolder (e.g. http://example.com/drupal), the absolute path would be /drupal/sites/default/files/images/abc.jpg.


    As I explained in my answer on the same question you deleted, if you are trying to programmatically generate the path (that is, you do not know where the file directory is), you need to use file_directory_path():

    $image = file_directory_path() . "/images/abc.jpg";
    

    So if the files are in:

    • sites/default/files: $image = "sites/default/files/images/abc.jpg".
    • sites/example.com/files: $image = "sites/example.com/files/images/abc.jpg".

    Assuming your previous question is still the use-case, you should be using l() and theme_image() to generate the links and images, respectively, within your module. This will ensure the paths generated are correct given Drupal’s environment.

    Using the expected output you provided before, a solution would be:

    // Images are in drupalroot/sites/default/files/images
    $path = file_directory_path() . '/images/';
    
    $detail_file = 'detail_1.jpg';
    $image_file  = '1.jpg';
    
    $img = theme('image', $path . $image_file);
    
    $options = array(
      'attributes' => array(
        'title' => t('Sample title for image 1 lorem ipsum'),
      ),
      'html' => TRUE,
    );
    $output = l($img, $path . $detail_file, $options);
    

    So, assuming your site is at http://example.com/, the output would be:

    <a href="/sites/default/files/images/default_1.jpg" title="Sample title for image 1 lorem ipsum">
      <img src="/sites/default/files/images/1.jpg" height="<image height>" width="<image width>" />
    </a>
    

    But if your site was in a subfolder (e.g. http://example.com/drupal), the output would be:

    <a href="/drupal/sites/default/files/images/default_1.jpg" title="Sample title for image 1 lorem ipsum">
      <img src="/drupal/sites/default/files/images/1.jpg" height="<image height>" width="<image width>" />
    </a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some images that are wrapped within containers like this: <div id=swatchcontainer> <div
I have some static resources (images and HTML files) that will be localized. One
I have some images inside links that I want to essentially look like this:
I have some images that I'd like to draw a polyon around the outer
I have some images I would like to animate to 100% opacity once the
i have some images uploaded and their path in the database and add a
I have some images I am swapping out in a image widget by setUrl.The
I have some images (.bmp, .png, .jpg) in my directory. I want to convert
I am trying to have some images inside a div. Only one image should
I have some images that need to change, based not only on hover, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.