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

PHP list directories

P: 2
Hi

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...

root//

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
  2.  
  3. $dir="photo_upload"; // Directory where files are stored
  4.  
  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. }
  16.  
  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 mydomainname.com/directory name instead of mydomainname.com/photo_upload/directory.
Mar 30 '12 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
why should it go to example.com/photo_upload/directory? 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

Dormilich
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.