doujie4344 2017-04-27 23:46
浏览 68

在php中返回一个目录

I am building a wordpress site with galleries in it and want to add a 'Back to Gallery' link in my single-attachment.php that will send the user back one directory.

For example, if the image is at www.site.com/galleries/gallery1/image1/ I would want the link to send it back to www.site.com/galleries/gallery1/.

Any suggestions would be appreciated.

  • 写回答

1条回答 默认 最新

  • dszsajhd237437 2017-04-28 05:36
    关注

    You can either explode current URL,and remove last term from the URL and give it as link for Back to Gallery.

    <?php $url = explode('/', 'www.site.com/galleries/gallery1/image1/');
    array_pop($url);
    $back=implode('/', $url); 
    ?>
    <a href="<?php echo $back; ?>" >Back to Gallery</a>
    

    Or you can use $_SERVER['HTTP_REFERER'] for getting the previous URL.

    <a href="<?php echo $_SERVER['HTTP_REFERER']; ?>" >Back to Gallery</a>
    

    also by using javascript you can implement this in easy way :

    <a href="javascript:history.go(-1)" >Back to Gallery</a>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序