私は指定されたムービーディレクトリをスキャンし、forループとPHPを使用してウェブページ上にスタイルを表示するPHPスクリプトを持っています。コードは以下の通りです。私はグロブを使用しようとしましたが、一度アレイのすべての画像を取得したら、どのようにしてそれらをすべてのムービーと比較して、画像とムービーフォルダが一致して正しい名前で画像を表示するのですか?フォルダ内にすべてのイメージが表示されるようにする方法PHP?
<?php
// set dir to the directiry you want to index
$dir = 'Movies/';
// scanning the directory you set
$scan = scandir($dir);
// I have this value at 11 because the first movie shows up
// in the 11th file in the array
$file = 11;
// This then removes the first useless files from our array
$scanned = array_slice($scan, $file);
// gets the amount of files
$FileNum = count($scanned);
// display all images and fanart
$images = glob('*.jpg');
// for loop that goes through the array
for ($i = 0; $i <= $FileNum; $i++) {
// gives the class for styling
echo '<li class="image">';
これは私の質問を明確にする
`MOVIES---
\--random movies
\--mp4 and .jpg files`
で次のようにファイル構造がある問題のビット
// check if there is fanart/images in the folders
if (file_exists($dir . $scanned[$i] . $images)) {
// if there is images display them styled
echo '<img id="box1" src="' . $dir . $scanned[$i] . '*.jpg' . '" width="280" height="150" />';
} else {
// if not then display default image
echo '<img id="box1" src="http://placehold.it/280x150" width="280" height="150" />';
}
// make the box clickable to where the folder is located
echo '<a href="'. $dir . $scanned[$i] .'">';
// display the name of the movie and some JS
echo '<span class="text-content"><span>' . $scanned[$i] .'<br><br><i class="fa fa-4x fa-play-circle-o"></i><br><br><i class="fa fa-chevron-down" onclick="openNav()" aria-hidden="true"></i></span></span> </a>';
}
です - ファイルが存在するかどうかを確認する方法はある、と場合をそれは配列に入れますか?私はglobを使ってみましたが、ファイルが存在するかどうかを確認することはできません。
これをもっと具体的な、明確な質問にどのように絞り込むことができますか?つまり、私はこのような希望の行動をコード化することができますか?という質問がありますが、将来の読者にとってはあまり有用ではありません。あなたの質問を改善する方法については、[尋ねる]をチェックしてください。 – domsson
私は質問を変更しました。明確にするために、私が求めていたのは、ファイルが存在するかどうかをチェックする方法はありますか?そうであれば、配列に入れますか?私はglobを使ってみましたが、ファイルが存在するかどうかをチェックすることは考慮していません。 – HeroBrian