简体   繁体   English

用php打开一个文件夹并以html形式显示结果?

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

I have a basic php admin system on a website. 我在网站上有一个基本的php管理系统。

I can upload images normally but have to enter each dir location individually. 我可以正常上传图像,但必须分别输入每个目录位置。

I want to be able to type in the dir location and have the html form fields auto fill with the results from the folder. 我希望能够在dir位置键入内容,并让html表单字段自动填充文件夹中的结果。

I have done basic research into using readdir and glob functions. 我已经对使用readdir和glob函数进行了基础研究。

I managed to get results out with readdir but they came out random. 我设法用readdir得出结果,但结果是随机出现的。 Can anyone point me in the right direction? 谁能指出我正确的方向?

<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>

This is what I have so far, the echo in the form fields pushes out the first three letters of the filename. 到目前为止,这就是我所拥有的,表单字段中的回显会推出文件名的前三个字母。

If you want to get all the files in a folder you can use scandir . 如果要获取文件夹中的所有文件,可以使用scandir

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

You are creating $files array. 您正在创建$files数组。

Then attempting to pull values from $file . 然后尝试从$file提取值。

Note the (s) is missing. 请注意,缺少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM