문제

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

        }
    }
}
도움이 되었습니까?

해결책

Since PHP 5.2.0 pathinfo can do that as well:

$bareName = pathinfo($path_to_file, PATHINFO_FILENAME);

다른 팁

$text = "filename.test.php";

echo substr($text, 0, strrpos($text, ".")); //filename.test
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top