Connecting Tech Pros Worldwide Forums | Help | Site Map

is_file under windows

Tyno Gendo
Guest
 
Posts: n/a
#1: Apr 10 '07

How do you normally check filetypes? I ended up resorting to
!is_dir($file) as all other calls seem to fail so I had to assume if not
a directory its a file, rather than specifically checking if its a file.

I'm recursing a folder:

<?php
$cat_seq = 1;
$path = "e:\\videos\\$cat_seq";
$dh = opendir($path);
while ($file = readdir($dh)) {
echo filetype($file)."<br />";
if ( !is_dir($file) ) {
echo $file;
}
}
?>

Under windows, I can try is_file(), this always returns "" (nothing),
and if I try filetype($file) (as above on the echo) I can get 'dir' for
directories but get the following for files:

Warning: filetype() [function.filetype]: Lstat failed for <filename>


Tyno Gendo
Guest
 
Posts: n/a
#2: Apr 10 '07

re: is_file under windows


Tyno Gendo wrote:
Quote:
Under windows, I can try is_file(), this always returns "" (nothing),
and if I try filetype($file) (as above on the echo) I can get 'dir' for
directories but get the following for files:
>
Warning: filetype() [function.filetype]: Lstat failed for <filename>
>
I'm running PHP 5.2 on WinXP with Apache 2 if that helps.
Tyno Gendo
Guest
 
Posts: n/a
#3: Apr 10 '07

re: is_file under windows


Tyno Gendo wrote:
Quote:
Tyno Gendo wrote:
Quote:
>Under windows, I can try is_file(), this always returns "" (nothing),
>and if I try filetype($file) (as above on the echo) I can get 'dir'
>for directories but get the following for files:
>>
>Warning: filetype() [function.filetype]: Lstat failed for <filename>
>>
>
I'm running PHP 5.2 on WinXP with Apache 2 if that helps.
... I just uploaded to a linux server to test, same result. Files exist
because i'm just recursing a directory now and printing out the names of
things that it finds along with an is_file($file) as well, always
returns <blank:-/
Willem Bogaerts
Guest
 
Posts: n/a
#4: Apr 11 '07

re: is_file under windows


.. I just uploaded to a linux server to test, same result. Files exist
Quote:
because i'm just recursing a directory now and printing out the names of
things that it finds along with an is_file($file) as well, always
returns <blank:-/

What do you pass to the is_file() function? The full path or just the
"basename"?

--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Tyno Gendo
Guest
 
Posts: n/a
#5: Apr 11 '07

re: is_file under windows


Willem Bogaerts wrote:
Quote:
Quote:
>.. I just uploaded to a linux server to test, same result. Files exist
>because i'm just recursing a directory now and printing out the names of
>things that it finds along with an is_file($file) as well, always
>returns <blank:-/
>
>
What do you pass to the is_file() function? The full path or just the
"basename"?
>
In this instance I have passed fullname. I could try a chdir and then
is_file("./$file"); ?
Tyno Gendo
Guest
 
Posts: n/a
#6: Apr 11 '07

re: is_file under windows


Willem Bogaerts wrote:
Quote:
Quote:
>.. I just uploaded to a linux server to test, same result. Files exist
>because i'm just recursing a directory now and printing out the names of
>things that it finds along with an is_file($file) as well, always
>returns <blank:-/
>
>
What do you pass to the is_file() function? The full path or just the
"basename"?
>
Thanks Willem,

I changed the test code as follows and used chdir to move into the base
directory first, then I just opened "." as the directory and checked the
file, it works. Code as follows checking for video files in a category
folder:

<?php
$cat_seq = 1;
$path = "e:\\videos\\$cat_seq";
chdir($path);
$dh = opendir(".") or die('cannot open directory');
while ($file = readdir($dh)) {
if ( is_file($file) ) {
echo $file;
}
}
?>

Closed Thread


Similar PHP bytes