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条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP