473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PHP list directories

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
3 2087
Dormilich
8,658 Expert Mod 8TB
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
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
8,658 Expert Mod 8TB
then tell the link to go to that directory. PHP only lists the directory names, not the directory URLs.
Mar 30 '12 #4

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

Similar topics

3
by: Eclectic | last post by:
I have a script that reads all directory names within a specific location (only containing folders), then lists all jpeg files in those directories. Here is my script: function...
5
by: Tum | last post by:
Hi folks, I've been trying to make a decision and it's driving me crazy. Is a directory a file or is a directory NOT a file but a node? Should I have A)
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
14
by: kpp9c | last post by:
I would like to use the power of Python to build some list structures for me. Namely i have organized a bunch of folders that have soundfiles in them and would like Python to slurp up all the...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
3
by: rn5a | last post by:
I am not very sure whether I should have continued with my earlier thread or started a new thread whose subject matter was somewhat similar to the subject matter in this thread. Anyway after much...
1
by: rn5a | last post by:
A ListBox lists all the folders & files existing in a directory named 'MyDir' on the server. Assume that the ListBox lists 2 directories - 'Dir1' & 'Dir2' i.e. these 2 directories reside in the...
63
by: David Mathog | last post by:
There have been a series of questions about directory operations, all of which have been answered with "there is no portable way to do this". This raises the perfectly reasonable question, why,...
8
by: J. Frank Parnell | last post by:
Hi there, I got this directory tree listing function somewhere, it works great, but I want it to only list directories that do have one or more .jpgs inside. I tried getting a list of each dir's...
2
by: lilly07 | last post by:
I managed to find thelist of files in a directory as below: grep {/\.txt$/i} How do I use grep statement to list directories of statting name as test... Thanks and Regards
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.