Jump to content

Open Directory and List Folders


danscreations

Recommended Posts

Not sure what's going on with the coding I wrote but I have a simple part of a script that looks a specified folder and is suppost to get all the subfolders, sort them, and display them (in the form of a dropdown menu). For some reason some folders aren't showing up. My inital thought was the nameing but I have other cases where the missing subfolder from the list has a completely different starting letter (for sorting). Anyone have any idea whats wrong?

 

Example of actual contents:

C3

C4

C5

C6

C6 Z06

 

Example of what gets displayed in the dropdown (C6 is missing?!?!)

C3

C4

C5

C6 Z06

 


$model_folder = 'gallery/'.$make.'/';
$open_model = opendir($model_folder);
echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="gallery_model_select">';
echo '<select name="model" onchange="document.gallery_model_select.submit()"'; if(empty($make)){echo' disabled';} echo '>';
echo '<option value="">Select Model</option>';
while($display_model = readdir($open_model)){
if(is_dir($display_model)){
} else {
$model_files[] = $display_model;
}
}

sort ($model_files);
foreach ($model_files as $model_data){
echo '<option value="';
echo $model_data;
echo '" ';
if ($model_data == $model){
echo 'selected';
}
echo '>';
echo $model_data;
echo '</option>';
}

closedir($model_folder);

Link to comment
Share on other sites

oh the wonders of glob()...

 

$files=glob("gallery/$make/C*");

 

will make an array of all files in the gallery/$make directory that start with a C use that for your loops :P

 

Cool...only issue is it's not only folders with the same starting letter. I have another folder and here is the outcome.

 

Example of actual contents:

FIRST GEN

FBODY

 

Example of what gets displayed in the dropdown (FBODY is missing?!?!)

FIRST GEN

 

It seems consistant that I have issues in folders containing subfolders with the same starting letter but would like to make the coding globle as not all folders have sub folders that start with "C" or "F". Any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.