[英]how to read files saved on the server using php and make a call to that php page using ajax to display the list of files
如何使用php來保存服務器上文件夾中保存的所有文件的名稱。 然后使用ajax調用該php頁面以顯示該文件列表
這是顯示文件列表的代碼:
$dir = '/tmp'; // your directory path
$files = scandir($dir);
foreach ($files as $file)
{
if (is_file($file))
{
echo $file . '<br />';
}
}
這是用於顯示文件列表的HTML / JavaScript(如果強烈建議您使用jQuery,則為:):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>File list</title>
</head>
<body>
<div id="content"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$("#content").load('<your listing PHP URL>');
</script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.