简体   繁体   English

如何在PHP / HTML网页上显示目录文件?

[英]How to Display Directory Files on a PHP/HTML Webpage?

I am willing to show the files' list of a web directory on a web page. 我愿意在网页上显示网络目录的文件列表。

But I am not understanding about how to do that. 但是我不知道该怎么做。

Can any one give me some easy guideline so that I can do it? 谁能给我一些简单的指导,以便我做得到?

Better any raw code (HTML,CSS,PHP,JS) so that I can understand the way to do it. 最好使用任何原始代码(HTML,CSS,PHP,JS),以便我可以理解这样做的方式。

Depending on your web server, you can enable directory listing. 根据您的Web服务器,您可以启用目录列表。 For example, in apache, you can delete your index.html and index.php file and enable directory listing in your .htaccess file. 例如,在apache中,您可以删除index.html和index.php文件,并在.htaccess文件中启用目录列表。

If you're using PHP, use `scandir]( http://php.net/manual/en/function.scandir.php ) to read a list of files in the current directory and print them to the screen. 如果您使用的是PHP,请使用`scandir]( http://php.net/manual/en/function.scandir.php )读取当前目录中的文件列表并将其打印到屏幕上。

$files = scandir( "MY_DIRECTORY" );
foreach( $files as $file ){
   echo $file . "<br />";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM