Quite a while ago I decided to change the way filenames are formatted when users upload a file to my website(which was a great idea!) to include the UNIX_Timestamp in the filename, this proved very useful after unfortunately the timestamps associated with files in my database was wiped, the filename structure has changed considerably and I am currently trying to recover the valid timestamp from the filename, however so far I have only been able to recover half.
Beforehand, I structured the filename to be like this:
dcd1322318879.png – Letters prepended by the unix timestamp.
Then, I allowed people to start logging in and made the filename much more Human Friendly, they now read as follows;
username-09092012-183422.jpeg where username is the logged in users name. The problem I am having now is the fact that firstly, I am awful with regex, for the previous filenames(without the user data and human friendly date) my code was:
$newDate = preg_replace("/[^0-9]/","", $data['name']);
However obviously that will not work now as usernames can contain numbers, and therefore that number will also be included in the final number for the date.
I am currently wondering if there is anyway I can resolve this issue, I guess the fact I added hyphens(-) will be useful as I can use it as a separator, however I have no idea where to start. I need to just get the last two parts of the filename, which contain the date & time so I can then convert them into unix timestamps.
Any help is greatly appreciated
There you go, yet another way, including translation to unix timestamp: