我想從'圖像'文件夾創建自動完成。 「圖片」文件夾中有超過50張圖片。如何從文件夾中排列所有圖像名稱?如何從文件夾中排列文件的名稱?
的search.php
<?php
/*
* Load sample data
*/
include 'data.php';
/*
* Results array
*/
$results = array();
/*
* Autocomplete formatter
*/
function autocomplete_format($results) {
foreach ($results as $result) {
echo $result[0] . '|' . $result[1] . "\n";
}
}
/*
* Search for term if it is given
*/
if (isset($_GET['q'])) {
$q = strtolower($_GET['q']);
if ($q) {
foreach ($data as $key => $value) {
if (strpos(strtolower($key), $q) !== false) {
$results[] = array($key, $value);
}
}
}
}
/*
* Output format
*/
$output = 'autocomplete';
if (isset($_GET['output'])) {
$output = strtolower($_GET['output']);
}
/*
* Output results
*/
if ($output === 'json') {
echo json_encode($results);
} else {
echo autocomplete_format($results);
}
data.php
<?php
$data = array(/*
* image_name
*/);
HTML
<link rel="stylesheet" type="text/css" href="src/jquery.autocomplete.css">
<script type="text/javascript" src="src/jquery.autocomplete.js"></script>
<script type="text/javascript" src="src/jquery.min.js"></script>
<script>
$("#ac5").autocomplete('search.php', {
minChars: 1,
useDelimiter: true,
selectFirst: true,
autoFill: true,
});
</script>
<form>
<input type="text" id="ac5">
</form>
我使用jquery.autocomplete.js和不工作...
什麼?你想要什麼? – Rizier123
你想把一個目錄中的所有文件名放入一個數組中嗎?如果是這樣,然後使用'scandir'例如'$ files = scandir(「directory」);' – jakecfc1992
是否可以從文件夾創建數組[文件名]? – Foxpro