Page 1 of 1

Browse Folder and get file path

Posted: Sun Feb 25, 2007 9:17 am
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

Posted: Sun Feb 25, 2007 9:24 am
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 :)

Posted: Sun Feb 25, 2007 9:28 am
by benyboi
Ok, thanks.

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

Update you later.

Thanks

Posted: Sun Feb 25, 2007 3:44 pm
by benyboi
Whats the difference between

.
and
..

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

Thanks

Posted: Sun Feb 25, 2007 10:59 pm
by Begby
'.' is the current folder. You should code your script to ignore it.