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