realpath

(PHP 4, PHP 5, PHP 7)

realpath锟斤拷锟截规范锟斤拷锟侥撅拷锟斤拷路锟斤拷锟斤拷

说锟斤拷

realpath ( string $path ) : string

realpath() 锟斤拷展锟斤拷锟叫的凤拷锟斤拷锟斤拷锟接诧拷锟揭达拷锟斤拷锟斤拷锟斤拷锟� path 锟叫碉拷 '/./', '/../' 锟皆硷拷锟斤拷锟斤拷锟� '/' 锟斤拷锟斤拷锟截规范锟斤拷锟斤拷木锟斤拷锟铰凤拷锟斤拷锟斤拷锟斤拷锟斤拷氐锟铰凤拷锟斤拷锟矫伙拷蟹锟斤拷锟斤拷锟斤拷樱锟�'/./' 锟斤拷 '/../' 锟缴分★拷

锟斤拷锟斤拷

path

要锟斤拷锟斤拷路锟斤拷锟斤拷

Note:

Whilst a path must be supplied, the value can be blank or NULL In these cases, the value is interpreted as the current directory.

锟斤拷锟斤拷值

Returns the canonicalized absolute pathname on success. The resulting path will have no symbolic link, '/./' or '/../' components.

realpath() 失锟斤拷时锟斤拷锟斤拷 FALSE锟斤拷锟斤拷锟斤拷说锟侥硷拷锟斤拷锟斤拷锟节的伙拷锟斤拷

Note:

The running script must have executable permissions on all directories in the hierarchy, otherwise realpath() will return FALSE.

Note: 锟斤拷为 PHP 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫凤拷锟斤拷锟斤拷锟酵讹拷锟揭很讹拷平台使锟斤拷 32 位锟斤拷锟酵o拷锟斤拷 2GB 锟斤拷锟较碉拷锟侥硷拷锟斤拷一些锟侥硷拷系统锟斤拷锟斤拷锟斤拷锟杰凤拷锟斤拷锟睫凤拷预锟节的斤拷锟� 锟斤拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
5.3.0 锟斤拷之前锟侥版本锟叫o拷锟斤拷 *BSD 系统锟较o拷锟斤拷锟斤拷锟斤拷锟斤拷锟� path 锟斤拷锟斤拷锟节的伙拷锟斤拷realpath() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷系统锟斤拷锟斤拷锟斤拷锟斤拷 FALSE锟斤拷
5.0.0 锟节达拷之前锟侥版本锟叫o拷锟斤拷锟� path 锟斤拷锟斤拷锟剿空伙拷锟斤拷 NULL锟斤拷锟斤拷锟斤拷锟斤拷 realpath() 锟斤拷锟截脚憋拷锟斤拷前锟斤拷目录锟斤拷

锟斤拷锟斤拷

Example #1 realpath() 锟斤拷锟斤拷

<?php
chdir
('/var/www/');
echo 
realpath('./../../etc/passwd');
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

/etc/passwd

Example #2 Windows 锟较碉拷 realpath()

锟斤拷 Windows 锟较o拷realpath() 锟结将 unix 锟斤拷锟斤拷路锟斤拷锟侥筹拷 Windows 锟斤拷锟侥★拷

<?php
echo realpath('/windows/system32');
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

C:\WINDOWS\System32

锟轿硷拷

  • basename() - 锟斤拷锟斤拷路锟斤拷锟叫碉拷锟侥硷拷锟斤拷锟斤拷锟斤拷
  • dirname() - 锟斤拷锟斤拷路锟斤拷锟叫碉拷目录锟斤拷锟斤拷
  • pathinfo() - 锟斤拷锟斤拷锟侥硷拷路锟斤拷锟斤拷锟斤拷息