Page 2 of 3
Posted: Wed Apr 12, 2006 2:45 pm
by ozzy
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."
?>

Posted: Wed Apr 12, 2006 2:47 pm
by pickle
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.
Posted: Wed Apr 12, 2006 2:54 pm
by ozzy
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));
Posted: Wed Apr 12, 2006 3:30 pm
by pickle
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.
Posted: Wed Apr 12, 2006 3:40 pm
by ozzy
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
Posted: Wed Apr 12, 2006 4:12 pm
by pickle
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.
Posted: Wed Apr 12, 2006 4:23 pm
by ozzy
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."
?>
Posted: Wed Apr 12, 2006 4:34 pm
by pickle
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.
Posted: Wed Apr 12, 2006 4:41 pm
by ozzy
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
Posted: Wed Apr 12, 2006 4:44 pm
by pickle
Line 4 - you're missing a semi-colon.
Posted: Wed Apr 12, 2006 4:47 pm
by ozzy
Now im getting
Code: Select all
Parse error: parse error, unexpected ';' in /host/localhost/htdocs/dir/index.php on line 4
Posted: Wed Apr 12, 2006 4:51 pm
by pickle
You've also got unbalanced parenthesis

Posted: Wed Apr 12, 2006 4:55 pm
by ozzy
How do i fix a unbalanced parenthesis?
Posted: Wed Apr 12, 2006 5:00 pm
by pickle
Put an extra one in.
Look at line 4. Just look at it - it doesn't look right.
Posted: Wed Apr 12, 2006 5:19 pm
by ozzy
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.