By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,748 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,748 IT Pros & Developers. It's quick & easy.

select a folder with option select in php

100+
P: 137
Hello guys,
I'm busy with an photogallery and i wanted to implent this script i wrote to select a folder and put there the photo's in.
But i only get 1 folder in the drop-down menu and the other is standing next to it.
If i do print_r ($folders); then the folders are side by side and the array has only index[0].
Anybody an idea?

this is my script:

[PHP]<? echo "<select name=\"selecteer folder\" size=\"1\" >";
$dir = ".";
$dp = opendir ($dir);
while ($folder = readdir($dp)){
if((is_dir($folder)) AND (substr($folder,0,1)!='.')){
$folders = explode (' ', $folder);
foreach ($folders as $index => $map){
echo "<option value=\"$index\">$map</option>";
echo "</select>";
$aantal = count ($folders); //For showing how many folders there are...(later use)
}
}
}
?>[/PHP]

Gr Paul
Feb 6 '07 #1
Share this Question
Share on Google+
3 Replies


ronverdonk
Expert 2.5K+
P: 4,258
You misplaced the end of select </select> statement. It should be outside the while loop\. I don't know what you want to do with the $aantal, so I left it where it was.

[php]<?
echo "<select name=\"selecteer folder\" size=\"1\" >";
$dir = ".";
$dp = opendir ($dir);
while ($folder = readdir($dp)){
if((is_dir($folder)) AND (substr($folder,0,1)!='.')){
$folders = explode (' ', $folder);
foreach ($folders as $index => $map){
echo "<option value=\"$index\">$map</option>";
$aantal = count ($folders); //For showing how many folders there are...(later use)
}
}
}
echo "</select>";
?>[/php]
Ronald :cool:
Feb 6 '07 #2

100+
P: 137
well, $aantal means total.
That one shows how many folders you have created.
You can cut it out...
but the problem is that.. hmm wait, an example:

these are the folders:
football
Holiday
Wedding

if i show the array it looks like this:
array([0}=>footbal) Holidayarray ([0]=>Holiday) Weddingarray([0]=>Wedding)

but it suposed to be:
array ([0]=>footbal [1]=>Holiday [2]=>Wedding)
Feb 6 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
Ik weet dat aantal total betekent.

The position of the $aantal assignment looks useless to me, because you fill that variable each time the foreach loop is executing. So at the end you have the value of the last assignment in variable $aantal.

Also, if you want to show the text 'Selecteer folder' in the top of your drop-down box, you must specify that text in the first <option> statement, along with a value of nil. Like this:[php]<?php
echo "<select name=\"selecteer folder\" size=\"1\" >";
echo "<option value=''>Selecteer folder</option>";
$dir = ".";
... etc ....[/php]
Ronald :cool:
Feb 7 '07 #4

Post your reply

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