weikelbob
asked on
How to echo what's in a directory on the server.
How do I echo a list of what's in a certain folder on my server?
I want to make a dropdown list that contains the names of the files in a directory using PHP
Thanks!
I want to make a dropdown list that contains the names of the files in a directory using PHP
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you'll need to change the directory to the one you want
ASKER
Awesome.
Will it bother you if I leave this question open over the next week while I play with this?
If so, I'm happy to close it sooner.
Thanks!
Will it bother you if I leave this question open over the next week while I play with this?
If so, I'm happy to close it sooner.
Thanks!
I have no problems with that as long as any follow up questions relate to the initial one.
ASKER
Very well, they would be.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, so for cx323's script to work I have to run phpinfo and get the whole directory structure of my server?
Both ways sound useful.
Both ways sound useful.
ASKER
How do I use getcwd to view a directory that is one level back?
Say I'm in an admin directory
/pages/admin/currentfile.p hp
and I want to make a dropdown box of the files in
/pages/music/
and only the files that have the extension .mp3
How do I do that?
Say I'm in an admin directory
/pages/admin/currentfile.p
and I want to make a dropdown box of the files in
/pages/music/
and only the files that have the extension .mp3
How do I do that?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry i think i did not read your question properly so here it goes again
i dont think that getcwd() can do this as it returns only the current working direcoty
http://php.net/getcwd
and you can try some code like as per your requirements
<?php
if ($handle = opendir('C:wamp\www\pages\ music'))
{
echo '
<form>
<select name="dir_files">';
while(false !== ($file = readdir($handle)))
{
$file_exp = explode(".", $file);
if($file_exp[1] == 'jpg')
{
$my_file = $file_exp[0].'.'.$file_exp [1];
echo "<option value='my_$file'>my_$file< /option>";
}
}
closedir($handle);
echo '
</select>
</form>';
}
?>
i dont think that getcwd() can do this as it returns only the current working direcoty
http://php.net/getcwd
and you can try some code like as per your requirements
<?php
if ($handle = opendir('C:wamp\www\pages\
{
echo '
<form>
<select name="dir_files">';
while(false !== ($file = readdir($handle)))
{
$file_exp = explode(".", $file);
if($file_exp[1] == 'jpg')
{
$my_file = $file_exp[0].'.'.$file_exp
echo "<option value='my_$file'>my_$file<
}
}
closedir($handle);
echo '
</select>
</form>';
}
?>
ASKER
OK.
I got a dropdown box working, btw, it's great.
I'll add this code to specify only a certain extension.
Thanks!
I got a dropdown box working, btw, it's great.
I'll add this code to specify only a certain extension.
Thanks!