stat(file) question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

stat(file) question

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

the filename has to be a string

example:

print_r(stat("file.php"));
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

I got it to work, thanks. Anyway to get the output vertically like your post? Mine is all jumbled up going horizontally.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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")));
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 ")";

?>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=45741 may be of interest.
Post Reply