Im working on a Dropdown menu which lists all files in a specific folder. In general it works pretty well. However the Dropdown menu shows all PDF files in the folder declared (which is great!) but also shows "." , "..", and "@eaDir" in the dropdown menu (which isnt that great!)
Ive tried to add something like this
$ignoredFiles = array('.', '..', '@eaDir');
But it dont quite know where to call this to execlude all the extentions
This is my PHP Code
<select name="euvertragsklausel" id="euvertragsklausel" class="pdfliste">
<option value="">- Verfahrensverzeichnis -
<?php
$dirPath = dir('euvertragsklausel');
$ignoredFiles = array('.', '..','@eaDir');
$FileArray = array();
while (($file = $dirPath->read()) !== false)
{
$FileArray[ ] = trim($file);
}
$dirPath->close();
sort($FileArray);
$c = count($FileArray);
for($i=0; $i<$c; $i++)
{
echo "<option value=\"" . $FileArray[$i] . "\">" . $FileArray[$i] . "</option>\n";
}
?>
</select>
<input type="button" class="btn btn-warning btn-xs" value="PDF Öffnen!"
onclick="gotoeuklausel()">
<br /><br />
And my Javascript. However i dont think the problem is in here
function gotoeuklausel(){
if(document.getElementById('euvertragsklausel').value) {
window.location.href = "content/dokumente/euvertragsklausel/"+document.getElementById('euvertragsklausel').value;
}
}
Just use in_array function
while (($file = $dirPath->read()) !== false)
{
if (! in_array($file, $ignoredFiles)) {
$FileArray[ ] = trim($file);
}
}