Question

I am trying to create a dropdown selectbox using every (video) file in a directory X as a seperate linked <option value=""></option>.

This is my first attempt:

<div align="center">
<form name="box">
<select name="select_clip" id="select_clip">
    <option value="">---Select Clip---</option>

<?php
$folder = "/volume1/folder/clips";
$allfiles = scandir($ordner);
foreach ($allfiles as $file) {
    $fileinfo = pathinfo($folder."/".$file); 
    $size = ceil(filesize($ordner."/".$file)/1048576); 
    if ($file != "." && $file != ".."  && $file != "_notes" && $file != "@eaDir" && $file != "index.html") { 
        while($file != NULL){?>
            <option value="/*Link to file*/ <?php echo $fileinfo['basename'];?>"><?php echo $fileinfo['filename'];?></option>
<?php
        };
    };
};
?> 

    </select>
    <input type="button" name="Submit" value="Watch Now!" onClick="window.open(select_clip.value,'newtab'+select_clip.value)">
    </form>
</div>

I know at what point is my mistake but I don't know how to fix it.

If I click the "Watch now" button a new tab appears (as suggested) but the url in the new tab includes an fail. It links the Link correctly but the part after that is wrong:

<?php%20echo%20$dateininfo[%27basename%27];?>
Was it helpful?

Solution

I would recommend something like this:

<?php

if ($handle = opendir('/path/to/files')) {

    $ignoredFiles = array('.', '..', '_notes', '@eaDir', 'index.html');

    while (false !== ($entry = readdir($handle))) {
        if(in_array(pathinfo($entry, PATHINFO_BASENAME), $ignoredFiles)) continue;
        echo "<option value=\"LinkToFile " . pathinfo($entry, PATHINFO_BASENAME) . "\">" . pathinfo($entry, PATHINFO_FILENAME) . "</option>";
    }

    closedir($handle);
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top