Reputation: 33
How do I get the files displaying without the file extension?
Currently I get a file like logo.png
but I only need the file name logo
.
if (is_dir($dir_path)) {
$files = scandir($dir_path);
foreach($files as $file) {
if ( !in_array( $file, $exclude_all ) ) {
$path_to_file = $dir_path . $file;
$extension = pathinfo ( $path_to_file, PATHINFO_EXTENSION );
$file_url = $dir_url . $file;
echo 'Path to file: ' . $path_to_file . '<br />';
echo 'Extension: ' . $extension . '<br />';
echo 'URL: ' . $file_url . '<br />';
}
}
}
Upvotes: 1
Views: 4299
Reputation:
$text = "filename.test.php";
echo substr($text, 0, strrpos($text, ".")); //filename.test
Upvotes: 0
Reputation: 437326
Since PHP 5.2.0 pathinfo
can do that as well:
$bareName = pathinfo($path_to_file, PATHINFO_FILENAME);
Upvotes: 3