用php打开一个文件夹,并在html表单中显示结果


Opening a folder with php and displaying the results in an html form?

我在一个网站上有一个基本的php管理系统。

我可以正常上传图像,但必须单独输入每个目录位置。

我希望能够在目录位置键入,并有html表单字段自动填充从文件夹的结果。

我已经对使用readdir和glob函数做了基本的研究。

我设法用readdir得到结果,但它们是随机的。有人能给我指个方向吗?

<body>
<p>
<?php
include 'mysqlconfig.php';
include 'opensqldb.php';
$files = scandir('photos');
foreach($files as $file) {
    echo $file ;
}
?>
</p>
<form id="form1" name="form1" method="post" action="">
    <label for="textfield"></label>
    <p>
        <input name="textfield" type="text" id="textfield" value="<? echo $file[0] ?>" />
    </p>
    <p>
        <input name="textfield2" type="text" id="textfield2" value="<? echo $file[1] ?>" />
    </p>
    <p>
        <input name="textfield3" type="text" id="textfield3" value="<? echo $file[2] ?>" />
    </p>
</form>
</body>

这是我目前为止所做的,表单字段中的echo将推出文件名的前三个字母

如果你想获取一个文件夹中的所有文件,你可以使用scandir。

<?php
    $files = scandir('uploads/');
    foreach($files as $file) {
        echo $file;
    }
?>

您正在创建$files数组。

然后尝试从$file中提取值。