By computerbarry on
Hi all
Quick question really, having trouble trying to get access to my root directory:
sites/default/files
I have a small snippet below which does the above, though my links are adding the active page url before the link url, causing missing images.
<img="
echo variable_get('file_public_path', conf_path() . '/files/') . $photo
">
Which produces:
http://localhost/example.dev/photo/sites/default/files/image1.jpg
The photo part being the page example.dev/page
Any ideas how to fix this?
Thanks, Barry
Comments
=-=
The question is best served in the 'module development and code questions' forum. Please edit the opening post and move it.Thank you.I've managed to fix it, not
I've managed to fix it, not sure if there is a better way?
Seems to work ok, for anybody interested:
Which outputs:
Barry
The more you learn.... the more you learn there is more to learn.
None of these are correct
None of these are correct really, there's API for returning the correct URLs but context means everything so it's hard to give you a properly "correct" answer without knowing exactly where you're planning to use it?
Ideally at a best guess, you just want to use the file stream wrapper - so;
<img src="<?php print file_create_url("public://photos/hello.jpg"); ?>" />Thanks pobester.
Thanks pobester.
Things seem to work ok as mentioned above, though certainly be interested if a better, more correct approach is required for this.
As things stand, I need to access the full URL/s, so no matter if I'm in dev, prod I will always get the correct full location of my assets folder:
$photo is the id of my photo/entity, which I then add a .jpg. I have hundreds of photos.
And are you saying what I'm doing is wrong?
Thanks, Barry
The more you learn.... the more you learn there is more to learn.