<body> <?php $song_name = $_POST['name_s']; $song_author = $_POST['author_s']; $song_year = $_POST['year_s']; $song_album = $_POST['album_s']; $song_dir = $_POST['dir_s']; /*директория с песней*/ echo "Директория: " . $song_dir . '<br>'; echo "Имя песни: " . $song_name . '<br>'; echo "Автор песни: " . $song_author . '<br>'; echo "Год записи песни: " . $song_year . '<br>'; echo "Альбом песни: " . $song_album . '<br>'; $handle = opendir($song_dir); $filename = 'visits.txt'; if ($handle != false) { if (is_writable($filename)) { $f = fopen('visits.txt', 'w+'); while (false !== ($file = readdir($handle))) { if ($file != '..' && $file != '.') { fwrite($f, $file . "\n"); } } fclose($f); } else { echo "Не могу произвести запись в файл $filename "; } closedir($handle); } ?> <?php echo 'Альбомы песни!<br/>'; $lines = file('visits.txt'); for ($i = 0; $i < count($lines); $i++) { $directory = trim($song_dir . $lines[$i]); echo "Выводим файлы каталога $directory"; if (is_dir($directory)) { /*открываем каждую папку*/ if ($handle2 = opendir("$directory")) { while (false !== ($file = readdir($handle2))) { if ($file != '..' && $file != '.') { echo "$file <br>"; } } closedir($handle2); } } else { echo "Неправильная директория </br>"; } } ?> </body> 

You need to create a PHP application consisting of two programs: a caching program and a search program. The caching program should examine the specified directory with music files on the hard disk, located in a subdirectory. The result of the study should be saved to a text file so that the second program can use it. When examining, you must determine the file name and its full path in the file system. If the file name contains the year of the song, artist, or album, they must be separately saved to the cache file and associated with the music file. The second program, the search program, should take the name of the song, artist, recording year, album as a parameter at launch. The user can enter one of the specified criteria or several. Criteria can be specified in whole or in part. For example, when searching for the song “I won't go Hollywood”, the user can only specify the word “Hollywood”. The program should find entries in the cache file that match the search criteria and show the full path to the found files in a list, arranging the records in the relevant order.

Ps. I made the output files, and then a stupor (you need to isolate the names of the song, album, year of recording in the full way, how to do it? I understand it to separate the full path with slashes, then just go over each line and search. If all the words match , then assign an index 1, if 2 then an index 2 and so on. I still can not write the full path to the file, tried the glob function, but there if there was a square bracket at the end of the folder. I did not recognize it as a folder.


 $dir = 'C:\Temp'; foreach (glob("$dir\\*.txt") as $filepath) { echo 'short name: ' . basename($filepath) . ' | '; echo "full path: $filepath | "; echo 'size :' . filesize($filepath) . "\n"; } // 

    1 answer 1

    Think about the format of the file names themselves, given the additional data for the year, the album, etc. Write them all possible in some example and think what is common. In these records. For example:
    artist_name-song name
    artist name_song-na-me
    etc. further for each record, make a search pattern using the preg * functions (preg_match for example). Work with templates.