如何阅读使用PHP保存在服务器上的文件和使用AJAX来显示文件列表拨打电话到PHP页面文件列表、拨打电话、器上、存在

2023-09-10 15:49:19 作者:始于初见、止于流言

如何增强抗辐射保存使用PHP的服务器上的文件夹中的所有文件的名称。 然后使用Ajax显示文件该列表拨打电话到PHP页面

how to rad the names of all files saved in the folder on the server using php. and then make a call to that php page using ajax to display that list of files

推荐答案

这是在code来显示文件列表:     

This is the code to display file list:

$dir   = '/tmp'; // your directory path
$files = scandir($dir);

foreach ($files as $file)
{
  if (is_file($file))
  {
    echo $file . '<br />';
  }
}

这是HTML / JavaScript来显示文件列表(如果你使用jQuery这是高度决定):

This is the HTML/JavaScript to display the file list (if you use jQuery which is highly advised):

<!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>