0

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.

Kevin
  • 41,694
  • 12
  • 53
  • 70
  • readdir/glob return filenames in the order they're stored in the filesystem. you'd have to do `$files = glob('*.*'); sort($files)` if you want them in-order. – Marc B Aug 13 '14 at 19:33

2 Answers2

0

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;
    }
?>
aarox04
  • 98
  • 6
0

You are creating $files array.

Then attempting to pull values from $file.

Note the (s) is missing.

CRABOLO
  • 8,605
  • 39
  • 41
  • 68
MrYellow
  • 426
  • 6
  • 23