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
https://forums.phpfreaks.com/topic/119663-open-directory-and-list-folders/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.