SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old August 13th, 2004, 03:35 AM
Krokman Krokman is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 Krokman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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);
?>


*************************

Reply With Quote
  #2  
Old August 13th, 2004, 04:14 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
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-

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Displaying contents of a folder with PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway