search
Homephp教程php手册PHP获取当前所在目录位置的方法,php获取当前所在

PHP获取当前所在目录位置的方法,php获取当前所在

本文实例讲述了PHP获取当前所在目录位置的方法。分享给大家供大家参考。具体分析如下:

如果要获取脚本文件的目录,要应用函数getcwd()来实现。函数声明如下:

string getcwd ( void ) ;

成功执行后返回当前目录字符串,失败返回FALSE。

示例如下:

下面将使用getcwd()函数来获取脚本文件的目录。代码如下:

复制代码 代码如下:

$shili= getcwd () ;      //获得当前脚本目录
$i = 0;
if ( is_dir ( $shili )){                   //检测是否是合法目录
   if ($shi = opendir ( $shili )){          //打开目录
      while ($li = readdir( $shi )){       //读取目录
   $i++ ;
    echo " $i: $li" ;      } } }     //输出目录中的内容
?>

运行结果如下图所示。

希望本文所述对大家的PHP程序设计有所帮助。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.