How to call an image from the file manager in a theme
Permalink
Trying to set up my client's site so they can change a background image in the header each month. My thinking is to keep one particular item in the file manager reserved for this use, and have them replace it when they want to update it.
Anyone have the code to pull an image from the file manager by name?
Anyone have the code to pull an image from the file manager by name?
I'm not sure how to get it by name, but you can get it by ID easily enough:
Jordanlev,
Got it working with a minor change:
and as the background image for the <div> in the header:
Appreciate the help.
Sherm
Got it working with a minor change:
<?php Loader::model('file'); $fileID ='450'; $f = File::getByID($fileID); $src = $f->getRelativePath(); list($width, $height) = getimagesize($f->getPath()); ?>
and as the background image for the <div> in the header:
<div id="headerwrap" style="background-image:url(<?php echo $src; ?>); background-repeat:repeat-x;">
Appreciate the help.
Sherm
Glad it worked for you.
Note that this is wrong and might cause problems down the road:
(I'm actually surprised it works now)
It should be just the $src.
$f is an object, not a string so echoing it doesn't actually do anything (except that sometimes it might give you an error or a warning, which is why you should not have it there). $f->getRelativePath() is the complete path and file name to the image (and since you assigned that to $src, that's why you only need to echo $src).
Note that this is wrong and might cause problems down the road:
<?php echo $src.$f; ?>
(I'm actually surprised it works now)
It should be just the $src.
$f is an object, not a string so echoing it doesn't actually do anything (except that sometimes it might give you an error or a warning, which is why you should not have it there). $f->getRelativePath() is the complete path and file name to the image (and since you assigned that to $src, that's why you only need to echo $src).
Fixed my original reply. Thanks for the clarification.
http://www.concrete5.org/documentation/developers/files/helpers...
-Steve