问题描述:

I need to show the files stored in a folder called "uploads" in a <select>. In this moment my code is the following:

<?php

echo "<select class='select' name='delete'>";

function get_directory22($path){

if (is_dir($path)){

$gestor = opendir($path);

while (($file= readdir($gestor)) !== false) {

$complete_path = $path . "/" . $file;

if ($file!= "." && $file != ".." && $file!= ".htaccess") {

if (is_dir($complete_path)) {

echo '<option value= "uploads/client1/' . $file. '"</option>';

get_directory22($complete_path);

} else {

echo 'error';

}

}

}

closedir($gestor);

} else {

echo "No es una ruta de directorio valida<br/>";

}

}

get_directory22("uploads/client1");

echo "</select>";

?>

I do not know why is it failing but the select shows nothing more than a white space.

网友答案:

Try replacing this line

echo '<option value= "uploads/client1/' . $archivo . '"</option>';

with this

echo '<option value= "uploads/client1/' . $archivo . '">' . $archivio . '</option>';

Also pressing F12 and looking at the html code of your website may help for future problems

网友答案:

Bad html:

     echo '<option value= "uploads/client1/' . $archivo . '"</option>';
                                                            ^---

You're generating

<option value= "uploads/client/1/foo/bar"</option>
                                         ^---missing >

Had you bothered opening your browser's 'view source' or DOM inspector, you'd have seen the mangled html right away.

相关阅读:
Top