List folders and subfolders in a combobox in php

0

I have this code:

<form action="" method="post" enctype="multipart/form-data" name="selecionar" id="selecionar">
Selecione a pasta que deseja enviar a imagem:<br>
  <select name="galeria" id="galeria">
<?php
	$diretorio = getcwd();
	$ponteiro = opendir($diretorio);
	while ($nome_itens = readdir($ponteiro)) {
		$itens[] = $nome_itens;
	}
	sort($itens);
	foreach ($itens as $listar) {  
		if ($listar!="." && $listar!=".."){       
			if (is_dir($listar)) {          
				$pastas[]=$listar;
			}else{            
				$arquivos[]=$listar;
				 }
			}
	}
	if ($pastas != "" ) {
		foreach($pastas as $listar)
	{  
?>
<option value="<?php echo $listar; ?>" selected="selected"><?php echo $listar;?></option>
<?php }  } ?>
</select>
<label></label>
<?php $pasta = $_POST['galeria']; ?>
<br />
<?php
$dir = $pasta . "/";
$ext = array("gif","jpg","png");
$campos = 3;
echo '<font face=Arial size=2><strong>Selecione as fotos que deseja enviar:</strong></font><br><br>
<input type="file" name="file[]"><br>
<input type="file" name="file[]"><br>
<input type="file" name="file[]"><br>
<input type="submit" name="submit" value=" Enviar ">
';
 if (isset($_POST['submit'])) {
$f_name = $_FILES['file']['name'];
$f_tmp = $_FILES['file']['tmp_name'];
$f_type = $_FILES['file']['type'];
$cont=0;
for($i=0;$i<$campos;$i++){
$name = $f_name[$i];
  if ( ($name!="") and (is_file($f_tmp[$i])) and (in_array(substr($name, -3),$ext)) ) {
    if ($cont==0) {
      echo "<b>Arquivo(s) enviados:
</b>";
    }
      echo $name." - ";
      $up = move_uploaded_file($f_tmp[$i], $dir.$name);
        if ($up==true):
            echo  "<i>Enviado!</i>";
              $cont++;
        else:
            echo "<i>Falhou!</i>";
        endif;

      echo "";
  }
}
echo ($cont!=0) ? "<i>Total de arquivos enviados: </i>".$cont : "Nenhum arquivo foi enviado!";
}
?>
<br />

</form>
<p><br />
  <?php echo $dir; ?><br />
  <br />
<br />

It even works, but not exactly how I would like it, in the combobox it just shows the "images" folder, I'm trying, however unsuccessfully, to make it show all subfolders in the "images" folder, so that save the user-uploaded image, it will be saved in the selected folder in the combobox.

In case it would look like this:
images | images / first folder
images / first folder / second folder
pictures / third folder
And so on.

    
asked by anonymous 29.03.2018 / 21:30

0 answers