Skip to content

Instantly share code, notes, and snippets.

@NandoKstroNet
Created May 17, 2017 22:03
Show Gist options
  • Save NandoKstroNet/14e314692a68b379d26c2a24393f92d3 to your computer and use it in GitHub Desktop.
Save NandoKstroNet/14e314692a68b379d26c2a24393f92d3 to your computer and use it in GitHub Desktop.
List files in a specific directory, in a pattern based.
<?php
$link = '';
$pattern = "*.pdf";
function mountLink(string $file, string $link, string $ext = '.pdf') :string
{
return "<a href=\"{$link}{$file}\" target=\"_blank\">" . str_replace($ext, '', $file) . "</a>\n";
}
foreach (glob($pattern) as $file) {
echo mountLink($file, $link);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment