By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,385 Members | 1,864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,385 IT Pros & Developers. It's quick & easy.

PHP list directories

P: 2

I'm having some trouble making a script to list a given directory at the root of my website.

Basically this is how I have it set up...


photo_upload <-- folder
proofing <--- PHP file

I want the proofing php file to LIST the folders inside the photo_upload.

If anyone could help, that'd be great.

Current this is the code that I have:
Expand|Select|Wrap|Line Numbers
  1. <?php
  3. $dir="photo_upload"; // Directory where files are stored
  5. if ($dir_list = opendir($dir))
  6. {
  7. while(($filename = readdir($dir_list)) !== false)
  8. {
  9. ?>
  10. <p><a href="<?php echo $filename; ?>"><?php echo $filename;
  11. ?></a></p>
  12. <?php
  13. }
  14. closedir($dir_list);
  15. }
  17. ?>
Problems with this code is that it lists all the files, and I just want the directories and when I click on the link, it goes to name instead of
Mar 30 '12 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 8,639
why should it go to you donít put the $dir directory in the URL of the link.
Mar 30 '12 #2

P: 2
because the folders i want to list are in photo_upload. so if they click on the links that were generated from the list, they'll go to to it.
Mar 30 '12 #3

Expert Mod 5K+
P: 8,639
then tell the link to go to that directory. PHP only lists the directory names, not the directory URLs.
Mar 30 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.