我的文件夹结构如下所示:
/articles .index.php .second.php .third.php .fourth.php
如果我在second.php中编写代码,如何扫描当前文件夹(articles)?谢啦,谢啦
1hdlvixo1#
$files = glob(dirname(__FILE__) . "/*.php");
http://php.net/manual/en/function.glob.php
d5vmydt92#
foreach (scandir('.') as $file) echo $file . "\n";
lnlaulya3#
从PHP manual:
$dir = new DirectoryIterator(dirname($path)); foreach ($dir as $fileinfo) { if (!$fileinfo->isDot()) { var_dump($fileinfo->getFilename()); } }
v1l68za44#
<?php $path = new DirectoryIterator('/articles'); foreach ($path as $file) { echo $file->getFilename() . "\t"; echo $file->getSize() . "\t"; echo $file->getOwner() . "\t"; echo $file->getMTime() . "\n"; } ?>
来自标准PHP库(SPL)
wwwo4jvm5#
这取决于你所说的“扫描”是什么意思,我假设你想做这样的事情:
$dir_handle = opendir("."); while($file = readdir($dir_handle)){ //do stuff with $file }
3wabscal6#
试试这个
$dir = glob(dirname(__FILE__)); $directory = array_diff(scandir($dir[0]), array('..', '.')); print_r($directory);
acruukt97#
扫描当前文件夹
$zip = new ZipArchive(); $x = $zip->open($filepath); if ($x === true) { $zip->extractTo($uploadPath); // place in the directory $zip->close(); $fileArray = scandir($uploadPath); unlink($filepath); } foreach ($fileArray as $file) { if ('.' === $file || '..' === $file) continue; if (!is_dir("$file")){ //do stuff with $file } }
chhqkbe18#
列出文件夹中的所有图像
$dir = glob(dirname(__FILE__)); $path = $dir[0].'\\images'; $imagePaths = array_diff( scandir( $path ), array('.', '..', 'Thumbs.db')); ?> <ul style="overflow-y: auto; max-height: 80vh;"> <?php foreach($imagePaths as $imagePath) { ?> <li><?php echo '<img class="pagina" src="images/'.$imagePath.'" />'; ?></li> <?php } ?> </ul>
8条答案
按热度按时间1hdlvixo1#
http://php.net/manual/en/function.glob.php
d5vmydt92#
lnlaulya3#
从PHP manual:
v1l68za44#
来自标准PHP库(SPL)
wwwo4jvm5#
这取决于你所说的“扫描”是什么意思,我假设你想做这样的事情:
3wabscal6#
试试这个
acruukt97#
扫描当前文件夹
chhqkbe18#
列出文件夹中的所有图像