douyuan6490 2015-06-17 10:39
浏览 37
已采纳

如何检查目录中的音频文件是否与存储在数据库中的文件名匹配

I have a database that contains the pathway to audio files. This data is stored in a column called Language1. The actual audio file is stored in a folder called Language1.

I want to check that the pathways in the database match the filename that is in the directory.

The first 10 files are in the folder, but the code is not recognising that. I want the code to read through each row in the database and compare that with the file names in the folder.

<?php
$servername = "localhost";
$user = "root";
$password = "root";
$dbname = "xxxx";

// Create connection
$conn = mysqli_connect($servername, $user, $password, $dbname);
$query = "SELECT Language1 FROM Table";
$result = mysqli_query($conn, $query);

while($row = mysqli_fetch_array($result))
{

$path = "/file/to/path/English/$Language1"; 
$Language1 = $row['Language1'];

if (file_exists($path)) 
    { 
 echo "The file $Language1 exists<br/>";
        } 
else
    { *
    echo "The file $Language1 does not exist<br/>";
    } 
} 
mysqli_close($conn);
?>
  • 写回答

1条回答 默认 最新

  • dongtuan1594 2015-06-17 10:57
    关注

    First generate the relative file path of each file from your working directory to the folder where the audio files are uploaded. then check if that file exist using the file_exists function. You can update the status of each files to a column in the table.

    http://php.net/manual/en/function.file-exists.php.

    Edited - sample code

    $username = "Name";
    $result = mysqli_query($connection, $sql);
    while ($row = mysqli_fetch_row($result)) {
        $filename = $row['filename'];
            $path = "/folder/".$username."/english/". $filename; 
        if (file_exists($path)) { 
            echo "The file $filename exists"; 
        } else { 
            echo "The file $filename does not exist";
        } 
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog