从其他驱动器获取MP3文件时出现问题



>我在显示来自另一个驱动器的 mp3 文件时遇到问题。在控制台中.log它显示错误已Failed to load resource: the server responded with a status of 404

现在我有音乐文件存储在D:music files 我的php文件路径是C:wampwwwphp examplesphp file handling systemfiles.php

现在,我如何从文件夹中获取音乐文件并将其显示在网页中D:music files

这是我的php代码:

 <?php
    $dir_path = 'D:music files';
    $options = '';
    if(is_dir($dir_path)){
        $files = opendir($dir_path);
        if($files){
            while(( $file_name = readdir($files)) !== FALSE){
                if($file_name != '.' && $file_name != '..'){
                    $op[] = array (
                        'name'=>$file_name
                    );
                    $options =  $options.'<option>'.$file_name.'</option>';
                    //echo $file_name."<br>";
                }
            }
        }
    }
?>

在 html 表格中显示

 <table class="table table-condensed table-bordered table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Music</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        $k = 1;
                        foreach($op as $row){
                    ?>
                        <tr>
                            <td><?php echo $k;?></td>
                            <td><?php echo $row['name']?></td>
                            <td><audio controls>
                              <source src="<?php echo $row['name'] ?>" type="audio/mpeg">
                            Your browser does not support the audio element.
                        </audio></td>
                        </tr>
                    <?php   
                            $k++;
                        }
                    ?>
                </tbody>
            </table>

提前致谢

来自 php 文档:

$dir    = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);

这列出了路径"dir"中的所有文件,您可以将其放入foreach并将音乐路径中的所有文件列出到表中,但是如果您只想获取所需的音乐文件,请使用glob。PHP 文档::全球函数

最新更新