Forum Moderators: coopster
Here's my existing form:
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><select>
(Here is where the folder names will be)
</select></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form>
If, for example, I have three folders titled "avatars", "banners", and "cats", I'll need the options to look like this:
<option value="avatars">avatars</option>
<option value="banners">banners</option>
<option value="cats">cats</option>
It needs to be dynamic, so coding it in static HTML isn't an option.
And then, I'll need to set the "value" to a variable...which I'm not 100% certain how to do.
Thanks in advance for any assistance. :)
//the path is valid
else{
foreach($path as $i){
echo("<option value=$i>$i</option>");
}//foreach
}//else
}//populateDropdown
now in your php file where the html table is put this call in
<select>
<?php populateDropdown(); ?>
</select>
Make sure you have that function somewhere in that file or in the php file you call. Just a note if there are files in that directory i.e. if avatars, banners, and cats, are there but so is test.txt that will be put in the dropdown also. to work around that you need to us the is_dir function. Let me know if you need anything else. I didn't test this so there may be a typo but I know the logic is right I deal with directories in PHP every single day.
//if they clicked the submit button
if(isset($_POST['submit'])){
$dropdownValue = $_POST['dropdown'];
//if the user selected avatars then the
//value of $dropdownValue will be == avatars etc.
//find the value of the dropdown
if($dropdownValue == "avatars"){
echo("You selected avatars");
}//if avatars
elseif($dropdownValue == "banners"){
echo("You selected banners");
}//elseif banners
elseif($dropdownValue == "cats"){
echo("You selected cats");
}//elseif cats
}if isset
//an array that is created from the individual folders
$arrName = explode("\\", $path);
//get the filename by grabbing the last thing in the array
$fileName = end($arrName);
return $fileName;
}//getFileName
Then in your foreach do this
foreach($path as $i){
//the \t will tab it over.
//if you want 2 then put \t\t
//the \n prints a carriage return so it is not all on one line in your html
echo("\t<option value=".getFileName($i).">".getFileName($i)."</option>\n");
}//foreach