How do I get a file name from a full path with PHP?

后端 未结 14 2416
花落未央
花落未央 2020-11-22 10:56

For example, how do I get Output.map

from

F:\\Program Files\\SSH Communications Security\\SSH Secure Shell\\Output.map

14条回答
  •  自闭症患者
    2020-11-22 11:14

    I've done this using the function PATHINFO which creates an array with the parts of the path for you to use! For example, you can do this:

    
    

    This will return:

    /usr/admin/config
    test.xml
    xml
    test
    

    The use of this function has been available since PHP 5.2.0!

    Then you can manipulate all the parts as you need. For example, to use the full path, you can do this:

    $fullPath = $xmlFile['dirname'] . '/' . $xmlFile['basename'];
    

提交回复
热议问题