php遍历文件夹获得所有文件名怎么办啊

WBOY
Release: 2016-06-23 14:12:59
Original
966 people have browsed it

php遍历文件夹获得所有文件名怎么办啊 网上找的 ,没有任何显示啊。是根目录下的a文件夹,我没有PHP开发技术。急用。。

<?php$dir = "/etc/php5/";if (is_dir($dir)) {if ($dh = opendir($dir)){       while (($file = readdir($dh)) !== false)       {         echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";       }       closedir($dh);}}?>
Copy after login


回复讨论(解决方案)

$dir = "/a/";

$dir = "/a/"; 没有任何反应。什么都不显示

可能代码哪里有问题,望帮助。

<ul><li><?php echo implode('</li><li>',scandir('/a')); ?></li></ul>
Copy after login

99 我啊 急

99 我啊 急

我给的代码用不了???
你直接复制到一个新的php文件里面运行就看到了。

<?php$dir = "/var/www/html/"; if (is_dir($dir)) {if ($dh = opendir($dir)){       while (($file = readdir($dh)) !== false)       {         echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";       }       closedir($dh);}}?>/*filename: .. : filetype: dir filename: index.html : filetype: file filename: . : filetype: dir filename: index.php : filetype: file filename: index.html~ : filetype: file filename: index.php~ : filetype: file */
Copy after login

可能有的原因是你的目录 $dir = "/etc/php5/"; 不存在,检查一下;

这样试一下,总该可以吧:

$dir = "c:/";

都辛苦了  ,$dir = "/a/";  改为 $dir = "a/"; 就可以了

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template