Page 1 of 1

Making a list as links

Posted: Mon Mar 27, 2006 1:10 am
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]

Posted: Mon Mar 27, 2006 1:13 am
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

Posted: Mon Mar 27, 2006 1:31 am
by sheepz
lol, thanks scott... you got it right on the dot... it does exactly what I wasked, thanks!

Posted: Mon Mar 27, 2006 1:38 am
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

Posted: Mon Mar 27, 2006 8:37 pm
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?