Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Display contents of a folder with php?
Old 01-22-2008, 04:19 PM Display contents of a folder with php?
freki's Avatar
Super Talker

Posts: 110
Name: Cody
Trades: 0
I'm trying to set up a 'sandbox' if you will on a domain. This is were I test all of my websites/designs before releasing them to the world.

My question is this: how would you go about making a php page that displayed the directories within a directory? I have a domain that is password protected and rejects robots/crawlers so my stuff hopefully doesn't get indexed. Each project of mine has it's own separate folder. When I put in my username/password (already set up) it directs to a new index page. I want that index page to dynamically list the folders within that directory. Does anyone know how to do this?

Thanks for any help
__________________
Get to know the real me -
Please login or register to view this content. Registration is FREE
freki is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-22-2008, 05:31 PM Re: Display contents of a folder with php?
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
The mod_dir module will help you.
http://httpd.apache.org/docs/1.3/mod/mod_dir.html

If you have it enabled requesting a directory (trailing slash) eg images/ will redirect to an index file if it exists.

By using the directive below (you can put it in your.htaccess in the root directory) will look for index.php specifically.

However if this file doesn't exist then it will generate its own index file of all files and directories. Therefore requesting http://example.com/ will give your standard home page but request a directory with no index.php page will generate its own index file. Obviously has security issues .

You can just use a script using scandir function. http://uk.php.net/scandir (php5).

Code:
 DirectoryIndex index.php
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 01-22-2008, 10:53 PM Re: Display contents of a folder with php?
freki's Avatar
Super Talker

Posts: 110
Name: Cody
Trades: 0
Thanks. The scandir function is more of what I was looking for. I'll play around with it and give it a try
__________________
Get to know the real me -
Please login or register to view this content. Registration is FREE
freki is offline
Reply With Quote
View Public Profile
 
Old 01-23-2008, 11:37 AM Re: Display contents of a folder with php?
starlord's Avatar
Extreme Talker

Posts: 209
Name: Darran
Trades: 5
have a look at AutoIndex ... no databases or messing about ..

http://autoindex.sourceforge.net/

Very cool piece of coding

Starlord
__________________
##
Please login or register to view this content. Registration is FREE
##
Please login or register to view this content. Registration is FREE
##

Please login or register to view this content. Registration is FREE
starlord is offline
Reply With Quote
View Public Profile
 
Old 01-24-2008, 01:48 PM Re: Display contents of a folder with php?
freki's Avatar
Super Talker

Posts: 110
Name: Cody
Trades: 0
That's pretty cool starlord, not exactly what I'm looking for, but I think I might find somewhere to use that.
__________________
Get to know the real me -
Please login or register to view this content. Registration is FREE
freki is offline
Reply With Quote
View Public Profile
 
Old 01-25-2008, 05:24 PM Re: Display contents of a folder with php?
Novice Talker

Posts: 5
Trades: 0
If you want to access a directory from within PHP, you can try opendir and readdir commands:

http://us3.php.net/manual/en/function.readdir.php

PHP Code:
if ($handle opendir('/path/to/files')){
    while (
false !== ($file readdir($handle)))
        echo 
"$file\n";
    
closedir($handle);

shaftian is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Display contents of a folder with php?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.24618 seconds with 12 queries