Basically, scandir() works once when the page loads but after interacting with a load function or changing the div contents to another php file it returns warnings and errors. Here are the simplified code snippets in question. I’d like to know why this happens because in a previous part of the system where I had this exact code, it never returned this type of error before and the difference was that the previous one had the code inside a function.
manfile.php
require_once 'scanfiles.php'
<label>Folder Loc:</label>
<select name="" id="">
<?php
foreach ($dir as $dira){ ?>
<option value="<?php echo $dira;?>"><?php echo $dira;?></option> <?php
}
?>
</select>
scanfiles.php
$directs = scandir("uploads");
unset($directs[array_search('.', $directs, true)]);
unset($directs[array_search('..', $directs, true)]);
$dir = array("uploads");
foreach($directs as $direc){
if(is_dir('uploads/' . $direc)) {
array_push($dir, $direc);
}
}
The error returning after interacting with the page consists of:
The output that works only once is correct: