Making a list as links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Making a list as links

Post by sheepz »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Sorry this is probably a simple question.  I want to make a php page that will automatically list all the files (usually .bat, .vbs, and exe) in a directory.  I'm using a while loop to make the list but I want to also make the list as links with the while loop is that possible?  I don't want to manually add each file as a link with <a href>  Here's what I have so far, any suggestions is greatly appreciated.

Code: Select all

<?
$dir_name="/Inetpub/wwwroot/";
$dir=opendir($dir_name);
$file_list="<ul>";

  while ($file_name=readdir($dir))
    {
       if (($file_name!=".") && ($file_name!=".."))
            {
 	 $file_list .="<li> $file_name";
            }
     }
$file_list .="</ul>";
closedir($dir);
?>

Code: Select all

<html>
<body>

<p>Files in: <? echo "$dir_name"; ?></p>
<p><? echo "$file_list"; ?></p>

</body>
</html>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

<? 
$dir_name="/Inetpub/wwwroot/"; 
$dir=opendir($dir_name); 
$file_list="<ul>"; 

  while ($file_name=readdir($dir)) 
    { 
       if (($file_name!=".") && ($file_name!="..")) 
            { 
     $file_list .="<li> <a href=\"".$dir_name.$file_name."\">$file_name</a>"; 
            } 
     } 
$file_list .="</ul>"; 
closedir($dir); 
?>
:?:

sorry if I misunderstood the question
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

lol, thanks scott... you got it right on the dot... it does exactly what I wasked, thanks!
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

hrm... it makes the list as links but when i click on the links it gives me a page cannot be found. How do i make the list of files link up with the actual files on the computer example

/inetpub/wwwroot/install1.bat
/inetpub/wwwroot/install2.bat
/inetpub/wwwroot/install3.bat

Make a while loop listing the files and having them as links. these are files so when i click on them it should ask if i would like to "open, save, or cancel" dialog box.

Pretty much like a directory listing but i want to be able to change and edit the page
sheepz
Forum Commoner
Posts: 58
Joined: Wed Jul 06, 2005 11:35 pm

Post by sheepz »

do i have to use the <a href> on all the files manually? or would I be able to do a loop that will list the files and link the files accordingly so when the user clicks on the link lets say Install.bat it will ask the user to "open or save" the file?
Post Reply