The pathinfo() function allows you to turn a filepath into an Array and then interact with the keys of the Array. You can grab the Filename, Extension, Folder Name and Basename.
pathinfo()
- https://www.php.net/manual/en/function.pathinfo.php
- https://www.w3schools.com/php/func_filesystem_pathinfo.asp
pathinfo.php
<?php
$filepath = "./folder/file.txt";
$filepathArray = pathinfo($filepath);
var_dump($filepathArray);
echo "<br><br>";
echo $filepath;
echo "<br>";
echo $filepathArray['dirname'];
echo "<br>";
echo $filepathArray['basename'];
echo "<br>";
echo $filepathArray['filename'];
echo "<br>";
echo $filepathArray['extension'];
?>
Be the first to comment