Page 1 of 1

stat(file) question

Posted: Fri Mar 24, 2006 8:35 am
by bruceg
I am testing out the function stat(file), which is supposed to return information on a file. Does this only work for PHP files? I wanted to see if it worked on an image eg: stat(image.jpg), but I get this warning error:

Warning: Division by zero in /hsphere/local/home/bruceg/inspired-evolution.com/stat.php on line 2

Warning: stat(): Stat failed for gif (errno=2 - No such file or directory) in /hsphere/local/home/bruceg/inspired-evolution.com/stat.php on line 2.

Also it doesn't work when I try stat(file.php).

I get the no such file or directory error even though both my test page and the file I am trying to get the information on are at the same directory level.

what gives?

Posted: Fri Mar 24, 2006 8:40 am
by s.dot
the filename has to be a string

example:

print_r(stat("file.php"));

Posted: Fri Mar 24, 2006 8:41 am
by s.dot
just tested it out

Code: Select all

print_r(stat("hmm.php"));
results in

Code: Select all

Array
(
    [0] => 2
    [1] => 0
    [2] => 33206
    [3] => 1
    [4] => 0
    [5] => 0
    [6] => 2
    [7] => 64
    [8] => 1143210267
    [9] => 1143196727
    [10] => 1143196632
    [11] => -1
    [12] => -1
    [dev] => 2
    [ino] => 0
    [mode] => 33206
    [nlink] => 1
    [uid] => 0
    [gid] => 0
    [rdev] => 2
    [size] => 64
    [atime] => 1143210267
    [mtime] => 1143196727
    [ctime] => 1143196632
    [blksize] => -1
    [blocks] => -1
)

Posted: Fri Mar 24, 2006 8:56 am
by bruceg
I got it to work, thanks. Anyway to get the output vertically like your post? Mine is all jumbled up going horizontally.

Posted: Fri Mar 24, 2006 9:03 am
by s.dot
in the browser mine displays like that too

so i just view source and copy the output

you could do this:

Code: Select all

echo nl2br(print_r(stat("file.php")));

Posted: Fri Mar 24, 2006 9:07 am
by s.dot
actually that didn't work. but this did

Code: Select all

<?php

$array = stat("hmm.php");
echo "Array (<br />";
foreach($array AS $k=>$v){
	echo "&nbsp;&nbsp;&nbsp;[$k] => $v<br />";
}
echo ")";

?>

Posted: Fri Mar 24, 2006 10:05 am
by feyd
viewtopic.php?t=45741 may be of interest.