php - How to extract value from an select option form which happens to be a name of directory -


honestly, i've got not sinle idea.

            <?php                 $somepath = 'randomfoldername';                 $dir = new directoryiterator($somepath);                 foreach ($dir $fileinfo) {                     if ($fileinfo->isdir() && !$fileinfo->isdot()) {                         echo '<option value="$fileinfo->getfilename[]">'.$fileinfo->getfilename().'</option>';                     }                 }         ?> 

tried echo , got

$fileinfo->getfilename

in result.

probably doing terribly wrong. not sure if know mean. want use value after being posted can't make work.

you need write value want value property of <option> tag.

try this:

            <?php             $somepath = 'randomfoldername';             $dir = new directoryiterator($somepath);             foreach ($dir $fileinfo) {                 if ($fileinfo->isdir() && !$fileinfo->isdot()) {                     $filename = $fileinfo->getfilename();                     echo '<option value="'.$filename.'">'.$filename.'</option>';                 }             }         ?> 

another thing should avoid inline code. if intend on using pure php should reduce <option>...</option> output variable , insert variable alone html.

            <?php             $somepath = 'randomfoldername';             $dir = new directoryiterator($somepath);             $options = '';             foreach ($dir $fileinfo) {                 if ($fileinfo->isdir() && !$fileinfo->isdot()) {                     $filename = $fileinfo->getfilename();                     $options .= '<option value="'.$filename.'">'.$filename.'</option>';                 }             }         ?>           ...          <select><?php echo $options ?></select> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -