I'm building a wiki website and everything works when I only use HTML and JavaScript:
i klick button and it opens it in an iframe
<ul id="myUL">
<li><span class="caret">Technik</span>
<ul class="nested">
<li><input class="btn" type="button" value="Audit" onclick="altPdf()" /></li>
</ul>
</li>
<li><span class="caret">Lager</span>
<ul class="nested">
<li><input class="btn" type="button" value="Broker" onclick="brPdf()" /></li>
<li><input class="btn" type="button" value="alt_WE" onclick="lrawePdf()" /></li>
</ul>
</li>
</ul>
function altPdf() {
var omyFrame = document.getElementById("myFrame");
omyFrame.style.display = "block";
omyFrame.src = dbw;
}
var wdb = "anleitungen/lager/Arbeitsanweisung Wareneingang Durschub & Broker.pdf";
Buttons work but for every PDF file I have to add several lines of code and set exact path.
this is how it is looking right now
I go over subdirectories and files and create list elements and buttons with a foreach loop in PHP, naming buttons after PDF files. This makes it easier to add or remove folders and files not having to alter code every time.
<?php
$mainDir = __DIR__.'/anleitungen';
$subDirectories = scandir($mainDir);
unset($subDirectories[0]);
unset($subDirectories[1]);
?>
<ul id="myUL">
<?php
foreach ($subDirectories as $subDirectory) {
?>
<li><span class="caret"><?= $subDirectory ?></span>
<ul class="nested">
<?php
foreach(glob($mainDir.'/'.$subDirectory.'/*') as $file){
$info = pathinfo($file, PATHINFO_FILENAME);
//print_r ($file);
?>
<li><input class="btn" type="button" value="<?= $info ?>" onclick="showPdf()"/>
</li>
<?php
}
?>
</ul>
</li>
<?php
}
?>
</ul>
function showPdf() {
var omyFrame = document.getElementById("myFrame");
omyFrame.style.display = "block";
omyFrame.src = $file[i];
}
But now none of buttons work because they don't have the source anymore. scandir
and glob
return an array and I name buttons after the array data. Can I put an onclick
function on the buttons so they open the PDF file they're named after? Like "button.getpathofvalue"
or something?
When I print_r
value of $file
I get path to file but can't open it.