eggleston Posted January 20, 2015 Share Posted January 20, 2015 Hello: How could I use php to automatically insert the correct 3 letter month abbreviations and four digit year in the following pdf filenames on the first of each month? (For example "...Feb2015.pdf" then "...Mar2015.pdf" and so on.... <div>Book One: <a href="http://monthlybookfiles.mysite.com/BookOne_Jan2015.pdf">Download Here</a></div> <div>Book Two: <a href="http://monthlybookfiles.mysite.com/BookTwo_Jan2015.pdf">Download Here</a></div> <div>Book Three: <a href="http://monthlybookfiles.mysite.com/BookThree_Jan2015.pdf">Download Here</a> </div> <div>Book Four: <a href="http://monthlybookfiles.mysite.com/BookFour_Jan2015.pdf">Download Here</a> </div> Please advise, Eggie Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted January 21, 2015 Share Posted January 21, 2015 Don't they already have them in your div list? Or are you trying to create this list? What are you starting with? Some array which contains what? Quote Link to comment Share on other sites More sharing options...
eggleston Posted January 22, 2015 Author Share Posted January 22, 2015 Hello: What I am asking is how to automatically create filenames based on the month/year so that the filename will be a clickable link each month that will point to a real file on a server. So knowing that the filename will always be month/year based, I need php to grab the abbreviated month and four digit year (both dynamic) on the first of each month and then add them to the url/filename (constant) so that we can avoid having to retype/edit the filename via ftp each month. Again, in the example: "MyFilename_Jan2015.pdf" or "MyFilename_Mar2015" Thanks for your help. Eggie Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 22, 2015 Share Posted January 22, 2015 Are you talking about when the files are uploaded to the server you want to name them with those date values? $date = date('MY'); //outputs 3 letter abbreviation followed by a 4 digit year, for the CURRENT MONTH/YEAR. $filename = 'MyFilename_' . $date . '.pdf'; //$filename is now "MyFilename_Jan2015.pdf" Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 22, 2015 Share Posted January 22, 2015 (edited) If all of these pdf's are being uploaded into a single directory, you can just use PHP's glob() function to retrieve all filenames from that dir. Let's say you had a dir, like /home/user/pdfs And in that dir you had: MyFilename_Jan2015.pdf MyFilename_Feb2015.pdf MyFilename_Mar2015.pdf And you wanted to list them all as links: foreach(glob('/home/user/pdfs/*.pdf') as $filename)) //grab all ".pdf" filenames from this dir { echo '<a href="/path/to/pdf/' . $filename . '">$filename</a><br>'; } Edited January 22, 2015 by CroNiX 1 Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 23, 2015 Share Posted January 23, 2015 If all of these pdf's are being uploaded into a single directory, you can just use PHP's glob() function to retrieve all filenames from that dir. This is a good approach. It ensures that you will not have links that go nowhere if you skip a month, and prevents you from having to do file checks on every date. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.