Closed Thread Icon

Topic awaiting preservation: File last modified in PHP (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12003" title="Pages that link to Topic awaiting preservation: File last modified in PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: File last modified in PHP <span class="small">(Page 1 of 1)</span>\

 
butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-17-2002 23:54

I'm trying to write a script that opens a directory, goes through all the files, and sorts them according to the times the files were last modified. I've got the part of the script done that gets the files. I'm running into trouble when I try to get the modified times for each file. I'm using the filemtime() function. The strange part is, I get a date and time that makes sense on the . and .. files in the directory, but the files *I* put there all have the exact time and date. Now this may not seem to strange except the date and time on all of them is "31 December 1969 16:00".

Can it be because the files are created on a windows machine?

Any thoughts on this would be appreciated.


-Butcher-

[This message has been edited by butcher (edited 01-18-2002).]

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 01-18-2002 00:18

getlastmod()

-mage-

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-18-2002 03:15

Thanks Mage

That gets the mod time on the script that's running. I want to get the last modified time of files in another directory so I can sort them newest to oldest for display on the page.

-Butcher-

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 01-18-2002 17:07

http://www.theprojects.org/dev/lastmodified.html

-mage-

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-18-2002 18:58

Butcher, filemtime() function is what you need. But, since it doesn't work in your script, the problem may be located somewhere else. Can you show me your script?


butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-18-2002 23:42

mr.maX

Thanks for asking.

First, here's the results of the script run on a directory on my site.
http://martysdesigns.com/jason/tulsa_tornado/test_sort.php

and pardon the script, it's just something I put together to check the output.

<?

$dir_name = getcwd(); //Get directory name of calling script
$dir_name = $dir_name . "/includes";

$dir = opendir($dir_name); //open directory for reading

$time_array = array();

while ($content = readdir($dir))
{
//load the file name and file time into array
array_push ($time_array, filemtime($content). "

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-19-2002 00:00

You didn't specify valid filename in filemtime() function call... It should be called like this:

filemtime($dir_name . "/" . $content)

BTW Have you seen my reply regarding web site accessing problems (MAX's World) that you had in this thread: http://www.ozoneasylum.com/Forum12/HTML/000624.html


butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-19-2002 00:30

I saw your reply in the other thread, I was working on that just before I came back here.

As for this thread, I made the change you suggested to the file name in the filemtime() function call with no change in the output. I even tried throwing in clearstatcache() just for good measure.

This is just not making any sense!

-Butcher-

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-19-2002 01:44

Hmm, I've tested your code from above (with my fix) and everything worked fine... Anyway, try the following *simple* script (put it in the *same* folder where all other files are located):

<?php

$dir = opendir(".");

while ($current = readdir($dir)) {
&nbsp;&nbsp;&nbsp;&nbsp;print date("j F Y H:i", filemtime($current)) . "<BR>" . $current . "<BR>";
}

closedir($dir);

?>


butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-19-2002 02:03

Yes, the script you wrote works from within the same folder I am trying to get the file info from. I modified my script and put it in the same file and it worked also.

Thanks, I thought I was going nutty! (short trip)

Now I still kinda have my original problem, how do I access this file information from a script running in another directory. The script is actually one level up from the file I want the info from. (Duh, you knew that from looking at the script).

If you might need to know why I want to do such a thing... I have an index template in one folder with a dropdown box for navigation. The dropdown box gets options from the content files located in the includes file within the parent directory. I want to be able to sort the options in the nav box and display them according to the last modified date of the include files, so the newest file is the first option in the dropdown box.

I hope everyone could follow that explination.

Thanks!

-Butcher-

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-19-2002 02:24

Ok, now that it partially works, let's try the following script (put it one level up from "includes" folder):

<?php

$dir = opendir("includes");

while ($current = readdir($dir)) {
&nbsp;&nbsp;&nbsp;&nbsp;print date("j F Y H:i", filemtime("includes/" . $current)) . "<BR>" . $current . "<BR>";
}

closedir($dir);

?>


butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-19-2002 04:15

Thanks mr.maX

That works for me. I was able to get the file names and time stamps, and sort them as needed. It works like a charm.

Thanks again!!

Oh... and thanks for your patience.

-Butcher-

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-19-2002 11:19

I'm glad that it finally works...


« BackwardsOnwards »

Show Forum Drop Down Menu