Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detect newest filename in a folder with multiple files?

    I am in a very tight time crunch to get this working, please if there is anyone who could help me with this I would GREATLY appreciate it. I have searched all over before I have posted to see if I could find a similar example but can't find any.. That I need to do is to have a php script scan a folder of about 12 files, detect by date/time modified which one is the newest and echo that files contents back. I already have most of that done, just need to figure out how to detect the newest filename. What I need to incorporate this into is the code below which currently only reads from one preset file. All that needs to be done is the filename variable needs to be determined based on newest xml file in the folder, which could have a variety of names, in the same folder this php script is located. Thank you so much to anyone who can help me out with this, this has to go live very early in the morning..

    Thanks!!
    Chris

    Code:
    <?php
    $filename = 'file.xml';
    $blank_file = 'blank.xml';
    
    if (file_exists($filename)) {
    		$xml = file_get_contents ($filename);
    		if (preg_match("#</(text1|text2)>#", $xml)) {
    		echo $xml;
    		} else {
    		$blank = file_get_contents ($blank_file);
    		echo $blank;
    		}
    } else {
    	$blank = file_get_contents ($blank_file);
    	echo "$blank";
    }
    ?>

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Without doing any testing, I know that filemtime() is what you're looking for.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •