Browsing for Empty Directory

All,

Looking for a way to browse and get empty directory. All the examples I see are using the:

<input type='file'>

with extra button, but that means you can not browse for an empty directory.

I’m sure there are good examples of this so would appreciate a quick shot with link to some source.

Thanks!

OMR

could you please clarify

All,

Got some code from another user with:

<?php
session_start();
$drives_list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$_DS_ = DIRECTORY_SEPARATOR;

//Set the default drive
$drive='C';
if(isset($_POST['drive']) && strpos($drives_list, $_POST['drive'])!==false)
{
    $drive = substr($_POST['drive'], 0, 1);
    //Reset path
    $_SESSION['path'] = '';
}
else if(isset($_SESSION['drive']) && strpos($drives_list, $_SESSION['drive'])!==false)
{
    $drive = substr($_SESSION['drive'], 0, 1);
}

//Set the saved path
$savedPath = (isset($_SESSION['path'])) ? $_SESSION['path'] : '';
if(isset($_GET['updirectory']) && strpos($savedPath, $_DS_)!==false)
{
    $savedPath = substr($savedPath, 0, strrpos($savedPath, $_DS_, -2)+1);
}

//Set the newFolder directory
$newFolder = (isset($_GET['folder'])) ? $_GET['folder'].$_DS_ : '';

//Determin the current path
$path = '';
if(is_dir("{$drive}:{$_DS_}{$savedPath}{$newFolder}"))
{
    $path = $savedPath.$newFolder;
}
else if (is_dir("{$drive}:{$_DS_}{$savedPath}"))
{
    $path = $savedPath;
}

//Save current drive and path to session
$_SESSION['drive'] = $drive;
$_SESSION['path']  = $path;

//Create select options of valid drives
$drive_options = '';
for ($i=0; $i<strlen($drives_list); $i++)
{
    $drive_letter = $drives_list[$i];
    if (is_dir("{$drive_letter}:{$_DS_}"))
    {
        $selected = ($drive_letter==$drive)?' selected="selected"':'';
        $drive_options .= "<option value=\\"{$drive_letter}\\"{$selected}>{$drive_letter}:</option>\
";
    }
}

//Get the current folder path
$full_path = "{$drive}:{$_DS_}{$path}";

//Get the list of subfolders for the current folder
$folder_list = '';
$upDirectory = "<img style=\\"border:0px;\\" src=\\"{$_PATHS['images']}up_directory.gif\\" alt=\\"Up One Directory\\">Up One Directory";
if($path!='')
{
    $folder_list .= "<a href=\\"{$_PATHS['current_web']}?action=browseFolder&updirectory=true\\">{$upDirectory}</a><br />\
";
}
else
{
    $folder_list .= "<span style=\\"font-style:italic;\\">{$upDirectory}</span><br />\
";
}

$folders = glob($full_path."*", GLOB_ONLYDIR);
foreach($folders as $folderPath)
{
    $folder = substr($folderPath,  strrpos($folderPath, $_DS_)+1);
    $folderURL = rawurlencode($folder);
    $folder_list .= "<a href=\\"{$_PATHS['current_web']}?action=browseFolder&folder={$folderURL}\\">$folder</a><br />\
";
}

?>
<html>
<body>
<div style="width:300px;">
    <form name="drive_select" action="<?php echo $_PATHS['current_web'].'?action=browseFolder'; ?>" method="post">
    Drive:
    <select name="drive" style="width:300px;align:right;" onchange="this.form.submit();">
      <?php echo $drive_options; ?>
    </select>
    </form>

    <form name="folder_select" action="<?php echo $_PATHS['current_web'].'?action=addFolder'; ?>" method="post">
    Current folder:
    <br />
    <textarea name="currentFolder" style="width:300;height:60px;background-color:#cecece;"><?php echo $full_path; ?></textarea>
    <br />
    Select a subfolder:
    <br />
    <div style="width:300px;height:200px;border:1px solid black;overflow:auto;padding:2px;">
    <?php echo $folder_list; ?>
    </div>
        <button type="submit" name="action" style="float:right;">Cancel</button>
        <button type="submit" name="action" style="float:right;">Add Current Folder</button>
    </form>
</div>
</body>
</html>

Basically does what I want but kinda messy as I want a single input field and single button on my form that calls a popup letting me select the directory.

I guess I could let this be my pop-up form, but not use to calling pop-ups so will need some help there, if I go that direction. Also I’m not opposed to a JS pop-up, which might be a quicker and easier solution.

If you know the answer, great!

Thanks!

OMR