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

Viewed 428995

For example, how do I get Output.map

from

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

with PHP?

14 Answers

Try this:

echo basename($_SERVER["SCRIPT_FILENAME"], '.php') 
$image_path = "F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map";
$arr = explode('\\',$image_path);
$name = end($arr);
<?php

  $windows = "F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map";

  /* str_replace(find, replace, string, count) */
  $unix    = str_replace("\\", "/", $windows);

  print_r(pathinfo($unix, PATHINFO_BASENAME));

?> 

body, html, iframe { 
  width: 100% ;
  height: 100% ;
  overflow: hidden ;
}
<iframe src="https://ideone.com/Rfxd0P"></iframe>

Related