簡體   English   中英

用php打開一個文件夾並以html形式顯示結果?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM