У меня есть раскрывающийся список, который отображает каталоги. Если я выберу один и нажмите кнопку «Отправить», действие будет выполнено. Теперь мне нужна вторая загрузка Button, которая сжимает файлы и загружает zip-файл. Моя проблема в том, что я не получу выбранный элемент в PHP. Вот мой код:PHP получить текст из списка извлечения
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<select name="myDirs" id="myDirs">
<option value="0" selected="selected">Select a folder</option>
<?php
foreach(glob('auswertung/*', GLOB_ONLYDIR) as $dir) {
$dir = str_replace('auswertung/', '', $dir);
echo '<option value="'.$dir.'">'.$dir."</option>\n";
}
?>
</select>
<input type="submit" name="submit" onclick="test()" />
<form method="POST" action=''>
<input type="submit" value="Download Files" name="download">
</form>
<script type="text/javascript">
function test(){
var e = document.getElementById("myDirs");
console.log(e.options[e.selectedIndex].value);
}
</script>
<?php
if (isset($_POST['download'])) {
$dirs = $_GET['myDirs'];
$files = array('auswertung/"'.$dirs.'"/Coordinates.txt', 'auswertung/"'.$dirs.'"/MagnetField.txt', 'auswertung/"'.$dirs.'"/Timestamps.txt');
/*$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);*/
}
?>
</body>
</html>
Я новичок в PHP. Я получаю следующее сообщение об ошибке:
Примечание: Не определено индекс: myDirs в C: \ PATH \ HTDOCS \ folder.php на линии 20
Что я делаю неправильно?