Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在口述中列出文件并存储用户选择_Php_Html - Fatal编程技术网

Php 在口述中列出文件并存储用户选择

Php 在口述中列出文件并存储用户选择,php,html,Php,Html,一般来说,我对php和html相当陌生。我正在开发一个弹出窗口,列出子目录中的文件,允许用户只选择一个,然后通过使用提交按钮将其发送到c程序 问题是,我不知道如何允许用户从列表中选择一个文件,并将所述选择存储在变量中 另外两项要求是: -c程序在父目录中 -只列出.txt文件 <!DOCTYPE html> <html> <body> <h1> Test</h1> <select name="test"> <?php

一般来说,我对php和html相当陌生。我正在开发一个弹出窗口,列出子目录中的文件,允许用户只选择一个,然后通过使用提交按钮将其发送到c程序

问题是,我不知道如何允许用户从列表中选择一个文件,并将所述选择存储在变量中

另外两项要求是: -c程序在父目录中 -只列出.txt文件

<!DOCTYPE html>
<html>
<body>
<h1> Test</h1>
<select name="test">
<?php
$dir="./files";

if (is_dir ($dir))
{
    if ($dh = opendir($dir))
    {
        while (($file = readdir($dh)) != false)
        {
             if ($file != ".." && $file != "." && strtolower(substr($file,strrpos($file,'.') +1)) == 'txt)
              {
                   echo "option value =\"$file\"> $file </option>";
               }
        }
    }
}
?>
</select>

<button = type="button" onclick="self.close()"> Cancel </button>
</body>
</html>

试验

明白了,很简单。现在我觉得自己像个白痴。谢谢你抽出时间

<form action="example.php" method="POST">
<select name="test" id="test">
<?php
$dir="./files";

if (is_dir ($dir))
{
    if ($dh = opendir($dir))
    {
        while (($file = readdir($dh)) != false)
        {
             if ($file != ".." && $file != "." &&  strtolower(substr($file,strrpos($file,'.') +1)) == 'txt)
               {
                   echo "option value =\"$file\"> $file </option>";
               }
        }
     }
}
?>
</select>
<input type="Submit" value="Ok">
</form>


向我们展示您已经为文件列表triedglob()尝试的内容,然后显示一个供选择的表单。如果您回答了自己的问题,请将其标记为已回答