dpz3471 2013-03-20 01:21
浏览 48
已采纳

PHP可以回显包含图像或文件的DIRECTORY的地址吗?

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!

  • 写回答

3条回答 默认 最新

  • dongxiane0395 2013-03-20 01:44
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮