1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Rep Power

    ftp file for automatic placement in drop down menu

    Is there a way to code a form using PHP so that any files FTP'd to a specified directory will automatically appear as drop down menu selections in the form?

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Rep Power
    Yes there is!

    Oh OK then, a couple of pointers - look in the PHP manual under the function readdir() and there you will find how to loop through the files in a directory.

    What I would do is to read these into an array, and populate your drop down menu from this array.

    Here is an example of a function to do this, this comes from oscommerce, the open source shop:

    PHP Code:
     function tep_make_pull_down_menu($name$values$default ''$params ''$required false) {
    $field '<select name="' $name '"';
        if (
    $params$field .= ' ' $params;
    $field .= '>';
        for (
    $i=0$i<sizeof($values); $i++) {
    $field .= '<option value="' $values[$i]['id'] . '"';
          if ( ((
    strlen($values[$i]['id']) > 0) && ($GLOBALS[$name] == $values[$i]['id'])) || ($default == $values[$i]['id']) ) {
    $field .= ' SELECTED';
    $field .= '>' $values[$i]['text'] . '</option>';
    $field .= '</select>';

        if (
    $required$field .= 'required';

    What this function needs is an array set up like this:
    PHP Code:
    $countries_array = array(array('id'=>'E''text'=>'England'), array('id'=>'S''text'=>'Scotland'), array('id'=>'W''text'=>'Wales'), array('id'=>'N''text'=>'Northern Ireland'), array('id'=>'I''text'=>'Eire')); 
    Which you pass to it as the variable $values.

    So all you need to do is to read the files from your directory, write them into an array set up like the one above, using 'id' and 'text' as the indices. If your filenames are the 'text' ones, the 'id' ones are the ones passed by your form.

    More than a couple of pointers in the end, hope it helps.

IMN logo majestic logo threadwatch logo seochat tools logo