0

I am using Wordpress and I like to serve a page with a link to download. That link points to a new file EACH DAY. Is there a plugin that can do this?

  • Store a list of filename per day
  • Rotate each day using the right filename

If not, I can work around by using some kind of hashkey + yyyymmdd in the filename too. But don't know how. Any help? Thanks.

0

1 Answer 1

2

Your idea of using the current date in the filename would be the easiest. In the template for your page, you could have the following to generate your current day link:

<a href="/path/to/file/filename_<?php echo date('Y-m-d') ?>.pdf">Today's file</a>

The above uses the PHP date function to create a filename with the current date appended to it in this format:

YYYY-MM-DD

So for today's date, the filename would be:

filename_2011-09-28.pdf

Update: Based on OP's comment, you could do the following:

  1. Create a shortcode. This would easily allow you to insert the PHP function call in any post you wanted to create the "Today's file" link in.
  2. In the shortcode, use the PHP hash function to take today's date and generate a hash value.
  3. You would then need to have the files on the server with an equivalent hash value in their file name for each day.

Shortcode

In your theme's functions.php file, you would define the following:

// Define the function that the [todays-file] shortcode wil invoke
// Purpose is to return the link with the hashed file name
function todays_file_func($atts) {

    // Generate the hash of today's date
    $salt = "A random string to make it harder to crack the hash";
    $dateHash = hash('md5', date('Y-m-d').$salt);

    // Output the link with today's filename
    return "<a href='/path/to/filename_".$dateHash.".pdf'>Today's file</a>";
}
add_shortcode( 'todays-file', 'todays_file_func' );

Then you just need to add the shortcode to any post:

[todays-file]
2
  • Yeah but I don't want people who download can guess the filename format and download the next day files. I guess I can use hashkey with some formula using timestamp. However, how do I insert php code within the post itself??
    – HP.
    Commented Sep 28, 2011 at 23:30
  • Added an update with answers to your comment questions.
    – Pat
    Commented Sep 29, 2011 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.