[英]Opening a folder with php and displaying the results in an html form?
我在网站上有一个基本的php管理系统。
我可以正常上传图像,但必须分别输入每个目录位置。
我希望能够在dir位置键入内容,并让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>
到目前为止,这就是我所拥有的,表单字段中的回显会推出文件名的前三个字母。
如果要获取文件夹中的所有文件,可以使用scandir 。
<?php
$files = scandir('uploads/');
foreach($files as $file) {
echo $file;
}
?>
您正在创建$files
数组。
然后尝试从$file
提取值。
请注意,缺少。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.