Jump to content

Recommended Posts

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

 

 

 

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

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"

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 by CroNiX
  • Like 1

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.