Fill select from folder

0

I have a index.php file inside which I have my select and I want to fill it with the files of a specific folder, but I get two points .. as shown in the image:

Code.

<select name="Combobox1" size="1" id="cmbimgprin" style="position:absolute;left:441px;top:377px;width:468px;height:28px;z-index:2;">
    <option>Seleccione una Opción...</option>
    <?
    $directorio = "D:\letritastv\imagenes";
    $sizekb = 0.0 ;
    $sizemb = 0.0 ;
    $dir=opendir($directorio);
    $file=array();
    while (($file = readdir($dir))!== false)
    {
    if ($file != '.' && $file != '..')
    {  
    ?>        
        <option><? $file?></option>      
    <?}}?>
 </select>
  

What is missing or redundant in this code?

    
asked by Estefani_Sanchez 04.05.2017 в 20:30
source

2 answers

0

A possible failure could be the opening of the label PHP , the normal would be <?php ... ?> (unless it has an additional configuration)

You can avoid so many openings and closing of keys to avoid confusion and possible syntax errors, printing the option directly with echo

Your code would look like this:

<?php 
 $directorio = "D:\letritastv\imagenes";
 $dir=opendir($directorio);
 while (($file = readdir($dir))!== false)
  {
    if ($file != '.' && $file != '..')       
        echo '<option>'.$file.'</option>';      
  }
?>
  

As an additional contribution I could read about the function    scandir ($ directory)

    
answered by 04.05.2017 / 20:56
source
0

Try something more similar to this:

<select name="s1">
      <option value="" selected="selected">-----</option>
  <?php 
       foreach(glob(dirname(__FILE__) . '/images/*') as $filename){
       $filename = basename($filename);
       echo "<option value='" . $filename . "'>".$filename."</option>";
    }
?>

</select> 

SOURCE

    
answered by 04.05.2017 в 20:55