Browse Folder and get file path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benyboi
Forum Commoner
Posts: 80
Joined: Sat Feb 24, 2007 5:37 am

Browse Folder and get file path

Post by benyboi »

Hello,

I am creating a blog for a company and they are most likely to want images in it. I could tell them to work out the path of the image but i would rather i could have some sort of folder browsing script so that they click on the file they want etc.

All i need to know is how to browse the folder. I can work the rest out.

Thanks,
Ben
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You can list files on your server by doing something like:

Code: Select all

$handle = opendir($path);
while (false !== $file = readdir($handle)) {
    echo $file . "<br/>";
}
closedir($handle);
Remember that "." and ".." will appear in the list of files. Also, directories and files will be found, so use is_dir() to check if it's a directory since you can't download a directory... you'll want to change $path to $path . "/" . $file if it's a directory.

Hopefully that was vague enough to push you in the right direction :)
benyboi
Forum Commoner
Posts: 80
Joined: Sat Feb 24, 2007 5:37 am

Post by benyboi »

Ok, thanks.

Looks like it'll do what i'm trying to do.

Update you later.

Thanks
benyboi
Forum Commoner
Posts: 80
Joined: Sat Feb 24, 2007 5:37 am

Post by benyboi »

Whats the difference between

.
and
..

I'm guessing that .. is parent folder but whats the . ?

Thanks
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

'.' is the current folder. You should code your script to ignore it.
Post Reply