|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Displaying contents of a folder with PHP
Hi All
New to PHP so bear with me. I need some help... I am using the following script to display the contents of a folder as hyperlinks on a web page. Firstly -- how do I get the results to display alphabetically? Secondly -- how do I prevent displaying the folder root as a URL? and thirdly is it possible to associate icons with each file type? Thanks Krok ******************** <?PHP /** // Define the full path to your folder from root $path = "//Serv1/Documents/MARKETING/"; // Open the folder $dir_handle = @opendir($path) or die("Cannot open the damn file $path"); // Loop through the files while ($file = readdir($dir_handle)) { if($file == "." || $file == "." || $file == "index.php" || substr($file,-3) == "txt" ) continue; $fichierexp = $path."/".$file.".txt"; $TheLinkedFile = $path."/".$file; if(file_exists($fichierexp)) { @$fp = fopen($fichierexp,'r'); echo "<a href=\"$TheLinkedFile\" target=\"blank\">".fgets($fp,999)."</a><br>"; fclose($fp); } else { echo "<a href=\"$TheLinkedFile\" target=\"blank\">".substr($file,0,44)."</a><br>"; } } // Close closedir($dir_handle); ?> ************************* |
|
#2
|
|||
|
|||
|
1) To display them alphabetically you will need to store them in some kind of data structure (probably just an array) then sort them before displaying them.
2) To splice strings look into the functions beginning str in the reference at php.net, specifically things like strpos that will help you find the location of characters in a string. Alternatively you can probably use regexs but I refuse to believe in their existence (don't ask). 3) If you get the file type first (from the array you stored them in to start with) you can write code to print a different image for each file type. Hope this helps, -KM- |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Displaying contents of a folder with PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|