简体   繁体   中英

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

I have a basic php admin system on a website.

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.

I have done basic research into using readdir and glob functions.

I managed to get results out with readdir but they came out random. 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 .

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

You are creating $files array.

Then attempting to pull values from $file .

Note the (s) is missing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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