We need a method (or whatever they are called there) in PHP, which returns a list of all references to files with a given extension (say, mp3). I didn’t write on a puff, I don’t know what's wrong with that.
|
2 answers
It is possible and from another site. You then need a parser.
- cURL 'ohm or file_get_content () get the page code.
- Regularly check all links.
|
in php this is good.
//Имя директории, в которой ищем. Если надо в нескольких, можно сделать цикл или рекурсию. $directory_name = 'path/to/directory'; //Список расширений. СОбственно, может приходить извне в виде строки через запятую. $extensions = array_flip(explode(',','mp3,xlsx,psd')); //Получаем список всех файлов в директории $all_files = scandir($directory_name); $selected_files = array(); foreach($all_files as $file){ if(isset($extensions[filename_extension(file)])){ $selected_files[] = $directory_name.'/'.$file; } } //ВЫВОД СПИСКА ФАЙЛОВ print(implode(',<br/>',$selected_files)); //Можно вывести прямо сразу ссылки: foreach($selected_files as $file){ printf('<a href="%s">%s</a>','http://example.com/'.$file,$file); } function filename_extension($filename) { $pos = strrpos($filename, '.'); if($pos===false) { return false; } else { return substr($filename, $pos+1); } } - I think the question was about parsing a page on the Internet, and not directories on the server ... - Mike
- if uv. @myvzar is right, then nothing at all) - knes
- Anyway, your code can be shortened $ files = glob ('*. {Php, txt}', GLOB_BRACE); - Mike
|