473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HREF Link to open newest file, or only file in drectory?

I am working on creating a link to a monthly updated pdf file. This link will be in over 100 places, so of course I don't want to update these everytime the file changes. If I can't find what I am looking for, I already use a filename.php file where I define('FILENAME_ABC','abc.php') and only update once - but if possible, I would like to keep this automated..... so I am hoping there is a piece of script I can use that will just pull the most recent file in a directory.

This usually updated monthly, but there maybe times when it is not, so there maybe an issue using a java/php script where i pull the month & year into the filename. I am hoping there is a function in PHP that can do it automaticly based on the file date.

Thank you,
Kristine
Dec 14 '06 #1
2 6033
michaelb
534 Expert 512MB
If filename includes the timestamp, you can use function scandir -
array scandir ( string directory [, int sorting_order [, resource context]] )

- and just pick up the first item in array (or the last item, depending on how you set parameter sorting_order)

If not, you still can use this function to get all files in given directory, then use the filemtime function on each file... get the time and figure out the last modified file.
int filemtime ( string filename )

I'm not sure if this is the best, or the most efficient approach, but it should work for you.
Dec 14 '06 #2
ronverdonk
4,258 Expert 4TB
There are 2 things to consider:
1. the name of the file as visually seen by the admin in the directory, that gives some assurance over the age of the file
2. you want a routine that returns the newest file, based on its system date.

For no 1 you must establish some file name convention, such as: My_name YYYY-MM-DD HHMMSS.inf
[php] // this way to construct a new file name
$outfile = "docs/My_name ".date("Y-m-d His").".inf";[/php]
2. a routine that, based on the above file name convention, returns the name of the newest file (last written). When you call this routine in the function that opens the file, you are sure to have the newest.[php]<?php
$path = "docs/";
// show the most recent file
echo "Most recent file is: ".getNewestFN($path);

// Returns the name of the newest file
// (My_name YYYY-MM-DD HHMMSS.inf)
function getNewestFN ($path) {
// store all .inf names in array
$p = opendir($path);
while (false !== ($file = readdir($p))) {
if (strstr($file,".inf"))
$list[]=date("YmdHis ", filemtime($path.$file)).$path.$file;
}
// sort array descending
rsort($list);
// return newest file name
return $list[0];
}
?>[/php]
Ronald :cool:
Dec 14 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sorby | last post by:
Hi I've been coding in PHP for a little while now and was starting to feel pretty confident but then realise I need to understand regular expressions to solve a particular problem I've got ......
11
by: Dana Smith | last post by:
Can anybody explain why when I have a hyperlink on a page with the code similar to below, after the user clicks on the link, the desired window opens but the page with the hyperlink changes to a...
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
1
by: nsvmani | last post by:
Hi, i am trying to get the FileOpen dialogue window as soon as clicked href link I am using IE6 with ActiveX enabled. Just need to get the File Open dialogue window when i click on the HREF links.It...
2
by: Mel | last post by:
I have a navigation page, very long list of urls and when you click a link it is opened in a new window. THE PROBLEM: When i scrolldown the navaigator and click on a link, it refreshes...
12
by: Inny | last post by:
Im trying to rewrite a link with a href function. I need to parse a query string within it ('+tid') But all attempts Have falied. The current onclick/ link function <a href="java...
10
by: pt36 | last post by:
Hi I have a page with a form and a textbox. before to submit the form I want to chek if the inserted value in the textbox is already present in a database. So I need to pass the textbox value...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.