2
が壊れていないか確認してくださいこれは、ソングクラスPHPは - オーディオファイルが
class Song extends CD {
private $id;
public function __construct($rack, $name, $id)
{
$this->id = $id;
parent::__construct($rack, $name);
}
public function getSelectedSongId() {
return $this->id;
}
public function getSelectedSongPath() {
$list = $this->getSongsList();
return $list[$this->id];
}
}
public function getSongInfo() {
$data = [
'name' => $this->getName(),
'size' => $this->getSize(),
];
return $data;
}
public function getSize() {
$path = $this->getPath() . '/' . $this->getName();
return filesize($path);
}
public function getName() {
return $this->getSelectedSongPath();
}
}
があると私は、ファイルがオーディオ拡張子を持っているかどうかを確認CDクラスがある曲のオブジェクト
public function getSong() {
return new Song($this->rackDir, $this->getLoadedDisc()->getName(), $this->song);
}
を作成するための方法であり、 。
class CD {
private $path;
private $name;
private $rack;
private $validExtensions;
public function __construct($rack, $name)
{
$this->rack = $rack . '/';
$this->name = $name;
$this->path = $this->rack . $this->name;
$this->validExtensions = ['mp3', 'mp4', 'wav'];
}
public function getPath() {
return $this->path;
}
public function getName() {
return $this->name;
}
public function getSongsList() {
$path = $this->rack . $this->name;
$songsList = [];
if (!is_dir($path)) {
return false;
}
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && in_array(strtolower(substr($file, strrpos($file, '.') + 1)), $this->validExtensions))
{
array_push($songsList, $file);
}
}
closedir($handle);
}
return $songsList;
}
}
ファイルがオーディオ拡張子のあるファイルだけでなく、実際のオーディオファイルであるかどうかをチェックしたいと思いますか? PHPでこれを行う方法はありますか?
[MIMEタイプ](http://php.net/manual/en/function.mime-content-type.php)をご覧ください。 – Kruser