473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Displaying filenames as Hyperlinks on a page?

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
6 1627
<?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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ralph Freshour | last post by:
I have a PHP web app using MySQL - when I save a .jpg file named test's.jpg I see that the filename on the unix server is: test\'s.jpg - the filename I end up saving in my SQL table is named...
3
by: mike | last post by:
Ok, Here's what I want to do. I want to be able to display all the files in a directory as links on webpage so that the user can just click the link to download the appropriate file. I can make...
1
by: Waguih Boctor | last post by:
Hi, I have a number of ASP pages where some JPGs and GIFs are displaying in the browser and some are not. I have included an excerpt from the HTML below. In this example, the gif file at the...
3
by: JimJones | last post by:
Hey, I don't really know much about ASP but I need some help modifying the way a field is currently displayed. Currently the ASP code inside my page is simply: <%=rs.Fields("Notes")%> ...
1
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for...
4
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option...
0
by: n33470 | last post by:
We have a web site that is being converted from the 1.1 format into 2.0. I've noticed that after the web project has been converted, the first time that the solution is opened in VS, all of the...
0
by: Marcus Kwok | last post by:
I have written a class (Windows Form) in Managed C++ that accepts an array of image filenames and will display them sequentially. All images will be the same size. I got it to work, but I know...
6
by: Valentijn | last post by:
Hi, What I want to build is a simple database that just conatins a table with filenames (maybe hyperlinks). The problem is that I want to be able to fill the table using a form and drag and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.