select a folder with option select in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djpaul
    New Member
    • Oct 2006
    • 137

    select a folder with option select in php

    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=\"selectee r folder\" size=\"1\" >";
    $dir = ".";
    $dp = opendir ($dir);
    while ($folder = readdir($dp)){
    if((is_dir($fol der)) 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
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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=\"selectee r folder\" size=\"1\" >";
    $dir = ".";
    $dp = opendir ($dir);
    while ($folder = readdir($dp)){
    if((is_dir($fol der)) 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:

    Comment

    • djpaul
      New Member
      • Oct 2006
      • 137

      #3
      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)

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        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=\"selectee r folder\" size=\"1\" >";
        echo "<option value=''>Select eer folder</option>";
        $dir = ".";
        ... etc ....[/php]
        Ronald :cool:

        Comment

        Working...