简体   繁体   中英

Linking files (php)


I asked before how to get the content of a directory and I got suggested dirscan() which was exactly what I needed.
Now I want it so that the files are links redirected to the corresponding file. So if there was a file named 'book.pdf', you could click it and it would open 'book.pdf'.
Right now I did this:

<?php 
$dir = '/books';
$files = scandir($dir);

foreach($files as $file) {
    echo "$file<br/>";
}
?>

Thank you!

Uh, make them links?

echo "<a href=\"$file\">$file</a>"

This is not so much about PHP, more about (very basic) HTML.

echo "<a href='$dir/$file'>$file</a>"

I'd say you just make them a html link? Quick piece of code:

  echo "<a href=\"{$dir}/{$file}\">{$file}</a><br/>";

what about using HTML anchor tag? <a href="/books/$file">$file</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM