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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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():So if the files are in:
$image = "sites/default/files/images/abc.jpg".$image = "sites/example.com/files/images/abc.jpg".Assuming your previous question is still the use-case, you should be using
l()andtheme_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:
So, assuming your site is at
http://example.com/, the output would be:But if your site was in a subfolder (e.g.
http://example.com/drupal), the output would be: