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
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 2:45 pm
Sorry about the double post, but i think i have got it
!!!
But one last question... well i think it will be may last...
<?php
$arrayFiles=glob('*.*');
if($arrayFiles){
foreach ($arrayFiles as
*WHAT_DO_I_PUT_HERE* ) {
echo "$filename size <br>";
}
}
else
echo"File not found."
?>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 12, 2006 2:47 pm
Almost there. You need to determine the modified time of every file returned by glob(),
before you loop through it. You also need to asort() the results so you get them in chronological order:
Code: Select all
$myArray = array("file1"=>1,"file2"=>10,"file3"=>3);//assume 1,10 and 3 are file modification times
asort(myArray);
$myArray is now:
"file1"=>1,
"file3"=>3,
"file2"=>10
You can then loop through the resulting array.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 2:54 pm
Hoe exactly do i get the times into
Code: Select all
array("file1"=>1,"file2"=>10,"file3"=>3);/
Do i put the filemtime function in there?
Code: Select all
. date ("F d Y H:i:s.", filemtime($filename));
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 12, 2006 3:30 pm
Yep. But filemtime() will give you a timestamp - which you can sort. Formatting the date before you sort may not give you 100% accurate results.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 3:40 pm
Cool.
But my current script is:
Code: Select all
<?php
$arrayFiles=glob('*.*');
if($arrayFiles){
foreach ($arrayFiles as . date ("F d Y H:i:s.", filemtime($filename)); {
echo "$filename size <br>";
}
}
else
echo"File not found."
?>
and i get this error:
Code: Select all
Parse error: parse error, unexpected '.', expecting '&' or T_STRING or T_VARIABLE or '$' in /host/localhost/htdocs/dir/index.php on line 5
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 12, 2006 4:12 pm
Line 5 is the foreach(). 3 things wrong with that line:
Don't put a period (.) between 'as' and 'date'
You can't put a function in the foreach like that. Just pull out the $filename, then call filemtime on that
Don't end that line with a semi-colon. A semi-colon means end-of-statement, and you're not done the foreach statement at that point.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 4:23 pm
So would this be right:
Code: Select all
<?php
$arrayFiles=glob('*.*');
$date=date ("F d Y H:i:s.", filemtime($filename)
if($arrayFiles){
foreach ($arrayFiles as $date) {
echo "$filename size <br>";
}
}
else
echo"File not found."
?>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 12, 2006 4:34 pm
Syntactically it looks ok. However, you're still missing the asort().
Read my previous comments - I've told you repeatedly what you need to do and in what order. Don't rely on me to tell you what you need to do - read the manual & the documentation for the functions and figure out what they do.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 4:41 pm
Just before i move on to the asort(), im having trouble with:
ozzy wrote:
Code: Select all
<?php
$arrayFiles=glob('*.*');
$date=date ("F d Y H:i:s.", filemtime($filename)
if($arrayFiles){
foreach ($arrayFiles as $date) {
echo "$filename size <br>";
}
}
else
echo"File not found."
?>
It is returning this error :
Code: Select all
Parse error: parse error, unexpected T_IF in /host/localhost/htdocs/dir/index.php on line 5
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 12, 2006 4:44 pm
Line 4 - you're missing a semi-colon.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 4:47 pm
Now im getting
Code: Select all
Parse error: parse error, unexpected ';' in /host/localhost/htdocs/dir/index.php on line 4
Last edited by
ozzy on Wed Apr 12, 2006 4:53 pm, edited 1 time in total.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 12, 2006 4:51 pm
You've also got unbalanced parenthesis
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 4:55 pm
How do i fix a unbalanced parenthesis?
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Apr 12, 2006 5:00 pm
Put an extra one in.
Look at line 4. Just look at it - it doesn't look right.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Wed Apr 12, 2006 5:19 pm
Code: Select all
<?php
$arrayFiles=glob('*.*');
$date=date ("F d Y H:i:s.", filemtime($filename));
if($arrayFiles){
foreach ($arrayFiles as $filename) {
echo "$filename <br>";
}
}
else
echo"File not found."
?>
It workes fine when i leave it as below
Code: Select all
foreach ($arrayFiles as $filename) {
Bust as soon as i change it to (see below) the files arnt displayed; the page is just blank apart from the <br>'s.