简体   繁体   中英

PHP scandir strange behaviour

ok, so what i'm trying to do is to scan the "previous" folder.

$scanned = scandir("..");
foreach($scanned as $file){

if(is_file($file)){
    print $file."<br />";       
   }
}

even though in my ".." directory i have 20+ files i get just three rows

index.jpg
index.php
template.dtd

i noticed that if i don;t use that is_file if clause it returns all file names; but i really need that if clause.

I'm going to take a while guess that those three files exist in both the current directory and the parent directory. scandir() only returns filenames, and you're calling is_file($file) when you mean is_file("../$file") .

Your function is testing for those filenames in the current directory and not in the previous directory. To get the desired result, try: is_file('../' . $file) instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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