doulin6448 2012-06-17 16:04
浏览 15

获取当前目录的文件夹名称[重复]

Possible Duplicate:
PHP Get name of current directory

Today I tried to get the folder name of a directory. I was successful to an extent. But it did not meet my criteria. The code which I have is as follows.

<?php
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : $_SERVER['REQUEST_URI'];
$foldername = basename($url);
echo $foldername;
?>

This returns the final value in an URL. I mean if the URL is localhost/default it returns default and when the url is localhost/default/index.php it returns index.php. I want it to return default in both the cases.

So is it possible to get the thing which I am expecting ?? Please help me out with that..

  • 写回答

2条回答 默认 最新

  • dphs48626 2012-06-17 16:07
    关注
    <?php 
    
    $url = "uour_url";
    $array = explode('/',$url);
    $count = count($array);
    echo $array[$count-2];
    
    ?>
    

    OR you can use getcwd(). This Function will return current directory.

    I have not tested it but hope it will helpful to you

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题