schris403 Posted March 13, 2008 Share Posted March 13, 2008 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.. What 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/95896-detect-newest-file-in-a-folder-with-multiple-files-and-echo-file-to-page/ Share on other sites More sharing options...
schris403 Posted March 13, 2008 Author Share Posted March 13, 2008 Sorry for screwing up the code brackets, here is my message again. 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 <?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"; } ?> Link to comment https://forums.phpfreaks.com/topic/95896-detect-newest-file-in-a-folder-with-multiple-files-and-echo-file-to-page/#findComment-490952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.