Can anyone tell me what’s wrong with this code? It is supposed to display all folders in ../files/, however, it is returning an empty list. This is the code:
<?php
$upload_dir = chdir("./files/" . $userid);
$dirs = glob($upload_dir, GLOB_ONLYDIR);
foreach($dirs as $val){
echo '<option value="'.$val.'">'.$val."</option>\n";
}
?>
You’ve got
$upload_dirset to the return fromchdir, which will be a TRUE or a FALSE, and then try to use that as your argument to glob when settings $dirs.The first argument to glob should be a string, representing a pattern. In your case, you’ll probably want * to list all contents (instead of the TRUE or FALSE you’re passing in). Think of the first argument to glob as what you would pas to
diron Windows, or tolsin Linux, so in this case/files/userid/*or something similar.I’d do something like this instead:
This has the advantage of not changing the current working directory. Ideally, I’d use an absolute path instead of the relative path there.