Question

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 />';

        }
    }
}
Was it helpful?

Solution

Since PHP 5.2.0 pathinfo can do that as well:

$bareName = pathinfo($path_to_file, PATHINFO_FILENAME);

OTHER TIPS

$text = "filename.test.php";

echo substr($text, 0, strrpos($text, ".")); //filename.test
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top