Reputation: 17321
I want to check files in directory and i'm using scandir()
and is_file()
for check. In this simple code is_file()
return false
for me. but in directory I have 3 file.
$files = scandir('uploads/slideShow');
$sfiles = array();
foreach($files as $file) {
if( is_file($file) ) {
$sfiles[] = $file;
// echo $file;
}
}
result for scandir()
with $file
s variable:
Array
(
[0] => .
[1] => ..
[2] => 6696_930.jpg
[3] => 9_8912141076_L600.jpg
[4] => untitled file.txt
)
result for $sfiles
:
Array
(
)
Upvotes: 4
Views: 4128
Reputation: 10212
that's beacuse you check if it's a file in the current dir, while the files reside in another dir... Try this:
$files = scandir('uploads/slideShow');
// ...
foreach($files as $file) {
if ( is_file('uploads/slideShow/'. $file) ) {
// file found!
}
}
Upvotes: 5
Reputation: 324650
The problem is that scandir
returns just the filename, so your code is looking for untitled file.txt
et al in the current directory, not the scanned one.
This is in contrast to glob("uploads/slideShow/*")
, which will returns the full path to the files you're looking at. If you use this glob
with is_file
, it should work fine.
Upvotes: 6