By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,828 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,828 IT Pros & Developers. It's quick & easy.

Displaying filenames as Hyperlinks on a page?

P: n/a
Hi,

I'd like to write a loop that will create a hyperlink on a page for
every single file on a directory. As an example, if my directory
contains:

test.txt
test1.txt
test2.txt,

The page should then contain 3 hyperlinks pointing to these files and
the user just have to click the one he wants to download or read.

Thanks.
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
<?php
$directory_name = "dir"; // change this to reflect your directory name
$dh = opendir($directory_name);
while ($file = readdir($dh)) {
if (is_dir("$directory_name/$file")) {
continue;
}
print "<a href=\"$directory_name/$file\">$file</a><br>\n";
}
closedir($dh);
?>
"circuit_breaker" <ci*************@canada.com> wrote in message
news:28**************************@posting.google.c om...
Hi,

I'd like to write a loop that will create a hyperlink on a page for
every single file on a directory. As an example, if my directory
contains:

test.txt
test1.txt
test2.txt,

The page should then contain 3 hyperlinks pointing to these files and
the user just have to click the one he wants to download or read.

Thanks.

Jul 17 '05 #2

P: n/a
On Tue, 30 Mar 2004 20:37:55 GMT, "kingofkolt" <je****@comcast.net> wrote:
while ($file = readdir($dh)) {


Until you have a file called '0', of course.

while (($file = readdir($dh)) !== false) {

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #3

P: n/a
you're right, i forgot about that...

another way to redo that line is:

while (!is_bool($file = readdir($dh))) {

because readdir() returns false when there are no more files

- JP

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:cl********************************@4ax.com...
On Tue, 30 Mar 2004 20:37:55 GMT, "kingofkolt" <je****@comcast.net> wrote:
while ($file = readdir($dh)) {


Until you have a file called '0', of course.

while (($file = readdir($dh)) !== false) {

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

Jul 17 '05 #4

P: n/a
kingofkolt wrote:
you're right, i forgot about that...

another way to redo that line is:

while (!is_bool($file = readdir($dh))) {

because readdir() returns false when there are no more files

- JP


Or, perhaps a bit more clearly,
while(($file = readdir($dh)) !== false)
Jul 17 '05 #5

P: n/a
On Tue, 30 Mar 2004 23:44:04 -0500, "Agelmar" <if**********@comcast.net> wrote:
kingofkolt wrote:
you're right, i forgot about that...

another way to redo that line is:

while (!is_bool($file = readdir($dh))) {

because readdir() returns false when there are no more files

- JP


Or, perhaps a bit more clearly,
while(($file = readdir($dh)) !== false)


There's an echo in here ;-) See the post he replied to but snipped ;-)

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #6

P: n/a
Andy Hassall wrote:
On Tue, 30 Mar 2004 23:44:04 -0500, "Agelmar"
<if**********@comcast.net> wrote:
kingofkolt wrote:
you're right, i forgot about that...

another way to redo that line is:

while (!is_bool($file = readdir($dh))) {

because readdir() returns false when there are no more files

- JP


Or, perhaps a bit more clearly,
while(($file = readdir($dh)) !== false)


There's an echo in here ;-) See the post he replied to but snipped
;-)


LOL I didn't look that far down. I just saw something incredibly ugly and
couldn't resist posting ^-^.
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.