Answer the question
In order to leave comments, you need to log in
How to display a list of files with links in the Bitrix directory?
There is a list of files, for example in /upload/
Files are not uploaded to the infoblock. It is necessary to display them in a list with download links.
From the infoblock is done like this:
<?foreach ($arResult["PROPERTIES"]["FILES"]["VALUE"] as $value):?>
<a href="<?=CFile::GetPath($value)?>">Скачать</a>
<?endforeach?>
Answer the question
In order to leave comments, you need to log in
use \Bitrix\Main\{ Application, IO };
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(Application::getDocumentRoot() . '/upload/MY_FOLDER/', \RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach($iterator as $item) {
if ($item->isFile()) {
$file = new IO\File($item->getPathname());
echo \sprintf('<a download href="/%s">%s</a>', \str_replace(Application::getDocumentRoot(), '', $file->getPath()), $file->getName());
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question