0

ファイル名を2つに分割して、phpなどを使用してループ経由でアクセスしたい。image_apple.jpg、image_mango.jpg、image_grapes.jpg など

各画像ファイルに対応する記述ファイルがあります

例: description_apple.txt

これらのファイルはすべて同じフォルダーにあります。

すべての画像と対応する説明ファイルを Web ページに表示したい

誰か助けてください よろしくお願いします

4

2 に答える 2

0

次のようなものを使用できます。

<?php
$files = scandir("./"); //./ is the current directory

foreach($files as $file) {
    $info = explode('_', $file); //Split on _

    //Skip all files withouth description
    if (count($info) <= 1) {
        continue;
    }

    $info = explode('.', $info['1']); //Split on .

    //Is there a file with description info?
    if (file_exists('description_' . $info['0'] . '.txt')) {
        $description = file_get_contents('description_' . $info['0'] . '.txt'); //$description contains the file description
    }
}
?>
于 2012-12-05T10:31:32.727 に答える
0

これを試して

    if ($handle = opendir('/folder path here/')) {



    while (false !== ($entry = readdir($handle))) {

    $names=explode("_",pathinfo($entry)['filename']);
    echo " desc: description_".$names[0].".txt";echo " name: image_".$names[1].".jpg";
        echo "<br>";
    }



    closedir($handle);
}
于 2012-12-05T10:32:42.920 に答える