SHORT VERSION OF MY QUESTION: Is there a way using PHP to echo the URL of the directory containing an image?
LONG VERSION: Hello all, I am working on a simple CMS (using Kirby in case it's relevant) and I've got almost everything working except for one thing. Kirby is a file-based CMS and each folder is its own page. I have it set so that all the images in a folder are automatically placed on the page. This is all working fine, but the thing is, I want to have a subfolder inside each project folder containing larger versions of the images. I don't want to use an automatic thumbnail plugin, or lightbox or anything like that. I'd like to manually save both versions of the image. I envisioned something like this: by clicking on the "thumbnail" image
website.com/projects/01-test/cat.jpg
could open a larger image
website.com/projects/01-test/large/cat-large.jpg)
I was hoping that I could somehow use PHP to display the full URL up to the directory of the image, but not the name of the image itself. The closest I have come is using:
<?php echo $image->url(); ?>
but that gives http://website.com/projects/01-test/cat.jpg while I just need http://website.com/projects/01-test.
If I could somehow automate this, then I figured I could do something like:
<a href="<?php echo $image->MYSTERY(); ?>/large/<?php echo $image->name(); ?>-large.jpg">
Okay, I hope this makes sense. I am learning PHP as I go along so I apologize if this has been covered before—I have tried searching everywhere but it might just be that I don't quite know what to search for. Any help you can offer would be greatly appreciated!
You're probably looking at dirname()
:
<?php echo dirname($image->url()); ?>
For example:
echo dirname('http://example.org/path/to/picture.jpg');
// http://example.org/path/to