Display datestamp script in HTML

Discussion in 'Javascript' started by Phil M, Mar 2, 2007.

  1. Phil M

    Phil M Guest

    Hi all. I have am HTML web page where I upload an updated file which
    is always called document.pdf. Users get there, click on the icon and
    download the document.pdf.

    Below the icon/link where users click to get document, is there any
    way to display the datestamp of document.pdf?

    ie: the document you're about to download was updated: March 2 2007

    My web page file name is called index.html (page where I want the
    datestamp to de displayed)
    The directory where I can store scripts is called /bin
    The file from which I want the datestamp to be retrieved is called
    document.pdf

    I searched the Internet for such a simple script but couldn't find
    any. I'm not a programmer, so please bear with me. What code do I
    have to paste in the index.html to display the actual datestamp of
    document.html? The server is Apache 1.3.26

    I was able to find the following code, but this displays the
    modification date of the HTML file itself, not from another file.

    <!--#config timefmt="%B %e, %Y"-->
    <script type="text/javascript">

    //Page Last Modified Date script- By JavaScriptKit.com
    //Visit http://www.javascriptkit.com for full source code
    //This notice must stay intact for use

    var docmodified='<!--#echo var="LAST_MODIFIED" -->'
    document.write('This page was last modified: '+docmodified)
    </script>


    Thanks for any suggestions!
     
    Phil M, Mar 2, 2007
    #1
    1. Advertising

  2. While the city slept, Phil M () feverishly typed...

    > Hi all. I have am HTML web page where I upload an updated file which
    > is always called document.pdf. Users get there, click on the icon and
    > download the document.pdf.
    >
    > Below the icon/link where users click to get document, is there any
    > way to display the datestamp of document.pdf?
    >
    > ie: the document you're about to download was updated: March 2 2007
    >

    [...]
    >
    > I was able to find the following code, but this displays the
    > modification date of the HTML file itself, not from another file.

    [...]

    Most likely because the javascript runs on the client, but you need
    information about a file on the server. You could do this with some pretty
    simple PHP which runs on the server-side. Something like, in your
    index.html;

    <!-- Start of example -->

    <p><a href="document.pdf>document.pdf</a> (last modified:
    <? php
    echo date("F d Y H:i:s.", filemtime("document.pdf"));
    ?>
    )</p>

    <!-- end of example -->

    .... and rename your index.html to index.php...

    I would recommend doing a test version first though just to make sure...

    Hope that helps.
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 2, 2007
    #2
    1. Advertising

  3. While the city slept, nice.guy.nige () feverishly
    typed...
    > <!-- Start of example -->
    >
    > <p><a href="document.pdf>document.pdf</a> (last modified:
    > <? php
    > echo date("F d Y H:i:s.", filemtime("document.pdf"));
    >>


    That last > should be a question mark (?) followed by a right angled bracket
    (>) as in ?>... but my newsreader decided to ditch the question mark... Just
    to clarify.

    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 2, 2007
    #3
  4. Phil M

    Phil M Guest

    >simple PHP which runs on the server-side. Something like, in your
    >index.html;


    Thanks for the code. As per the suggestion, I uploaded this:

    http://www.greekradio.net/psa.php
    and gives a parse error

    in case you can't see the source code here it is again in plian text:
    http://www.greekradio.net/psa.txt

    the page should look someting like this (plus the datestamp I'm trying
    to include)


    Thanks for any suggestions.
     
    Phil M, Mar 2, 2007
    #4
  5. Phil M

    Phil M Guest

    Phil M, Mar 2, 2007
    #5
  6. While the city slept, Phil M () feverishly typed...

    > Thanks for the code. As per the suggestion, I uploaded this:
    >
    > http://www.greekradio.net/psa.php
    > and gives a parse error
    >
    > in case you can't see the source code here it is again in plian text:
    > http://www.greekradio.net/psa.txt

    [...]

    My mistake, sorry... take out the space between the <? and php, so it reads
    <?php instead of <? php...

    (hangs head in shame!)

    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 3, 2007
    #6
  7. In comp.lang.javascript message <d0pgu29t0pqeinrr25g4psg18t5hbg3i37@4ax.
    com>, Fri, 2 Mar 2007 12:55:24, Phil M <> posted:
    >Hi all. I have am HTML web page where I upload an updated file which
    >is always called document.pdf. Users get there, click on the icon and
    >download the document.pdf.
    >
    >Below the icon/link where users click to get document, is there any
    >way to display the datestamp of document.pdf?


    That's susceptible to misleading if the PDF is ever re-uploaded without
    significant change.

    If you always ALSO upload to the same directory a file called
    document.js containing the line

    document.writeln("Date of document.pdf is YYYY-MM-DD")

    with the YYYY-MM-DD always set correctly, then the desired date should
    appear where you put
    <script type="text/javascript" src="document.js"></script> in your Web
    page.

    Maybe you can automate the generation of document.js .

    It's a good idea to read the newsgroup and its FAQ. See below.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Mar 3, 2007
    #7
  8. Phil M

    Phil M Guest

    Nige,

    To recapitulate, this is the code I have right now:

    <!-- Start of example -->

    <p><a href="document.pdf">document.pdf</a> (last modified:
    <?php
    echo date("F d Y H:i:s.", filemtime("document.pdf"));
    ?>
    )</p>

    <!-- end of example --></p>

    the result is this:

    http://www.greekradio.net/psa.html

    It doesn't display the date.

    Thanks for any suggestion.
     
    Phil M, Mar 3, 2007
    #8
  9. OT, PHP Solution To Problem (was Re: Display datestamp script in HTML)

    While the city slept, Phil M () feverishly typed...

    [...]
    > http://www.greekradio.net/psa.html
    >
    > It doesn't display the date.


    Change the filename to psa.php.

    Hope that helps.
    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 3, 2007
    #9
  10. Phil M

    OmegaJunior Guest

    On Sat, 03 Mar 2007 17:57:07 +0100, Phil M <> wrote:

    > Nige,
    >
    > To recapitulate, this is the code I have right now:
    >
    > <!-- Start of example -->
    >
    > <p><a href="document.pdf">document.pdf</a> (last modified:
    > <?php
    > echo date("F d Y H:i:s.", filemtime("document.pdf"));
    > ?>
    > )</p>
    >
    > <!-- end of example --></p>
    >
    > the result is this:
    >
    > http://www.greekradio.net/psa.html
    >
    > It doesn't display the date.
    >
    > Thanks for any suggestion.


    Maybe the document isn't as local as you think? Did you try
    filemtime("./document.pdf")? On some servers you have to tell the parser
    which directory to use. ./ should have the parser choose the same
    directory as the script.

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
     
    OmegaJunior, Mar 3, 2007
    #10
  11. Phil M

    Phil M Guest

    > Did you try filemtime("./document.pdf")?

    Thanks for the suggestion; I just tried the ./
    I don't think that's the problem as the above code prints the file
    link instead of the date, as shown here:
    http://www.greekradio.net/psa.html
     
    Phil M, Mar 3, 2007
    #11
  12. While the city slept, Phil M () feverishly typed...

    > Thanks for the suggestion; I just tried the ./
    > I don't think that's the problem as the above code prints the file
    > link instead of the date, as shown here:
    > http://www.greekradio.net/psa.html


    Did you change the file extension from .html to .php as I suggested in my
    post?

    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 3, 2007
    #12
  13. Phil M

    Phil M Guest

    >Did you change the file extension from .html to .php as I suggested in my

    Nige,

    Thanks for the tip(s). After renaming the html to php IT WORKED!
    here:
    http://www.greekradio.net/psa.php

    Isn't there any way to have this code with an html extension? If not,
    I'm not worried. As long as it works I'm happy with that. Thanks!

    Also, you may want to make this small and very efficient code
    available also in a pool because it may find good use among people
    with webcams. For example, every time a webcam a photo is uploaded,
    you code will display the datestamp and timestamp of the photo, rather
    than the date/time of the web page. Thanks.
     
    Phil M, Mar 3, 2007
    #13
  14. Phil M

    Phil M Guest

    >If you always ALSO upload to the same directory a file called
    >document.js containing the line


    Thank you for your suggestion. I'll give it a try.
     
    Phil M, Mar 3, 2007
    #14
  15. While the city slept, Dr J R Stockton ()
    feverishly typed...

    [document last saved]
    > That's susceptible to misleading if the PDF is ever re-uploaded
    > without significant change.


    Possibly, but then, what would an insignificant change be?

    > If you always ALSO upload to the same directory a file called
    > document.js containing the line
    >
    > document.writeln("Date of document.pdf is YYYY-MM-DD")
    >

    [...]

    Why would you want to suggest a javascript solution that relies on
    javascript being available *and* enabled in the end-users client, when a
    perfectly servicable php solution (which will serve the date to the end-user
    without the need for javascript to be available and enabled) has been
    offered to and used by the OP? Other than this being a javascript NG of
    course...

    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 3, 2007
    #15
  16. While the city slept, Phil M () feverishly typed...

    >> Did you change the file extension from .html to .php as I suggested
    >> in my

    >
    > Nige,
    >
    > Thanks for the tip(s). After renaming the html to php IT WORKED!
    > here:
    > http://www.greekradio.net/psa.php


    Great! Glad to hear (or more properly, read) it.

    > Isn't there any way to have this code with an html extension? If not,
    > I'm not worried. As long as it works I'm happy with that. Thanks!


    No, at least not without some serious tinkering with config files...
    However, .php files are more than perfectly acceptable. Of course, there may
    be an issue with persons who have bookmarked your .html version. In this
    case, it is fairly simple to write a basic redirect for your apache server
    so that any requests for psa.html get redirected to psa.php.

    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 3, 2007
    #16
  17. In comp.lang.javascript message <45e9ec84$0$97266$
    ..readfreenews.net>, Sat, 3 Mar 2007 21:44:44, nice.guy.nige
    <> posted:
    >While the city slept, Dr J R Stockton ()
    >feverishly typed...
    >
    >[document last saved]
    >> That's susceptible to misleading if the PDF is ever re-uploaded
    >> without significant change.

    >
    >Possibly, but then, what would an insignificant change be?


    Change of location (URL); correction of spelling mistakes; ...

    >> If you always ALSO upload to the same directory a file called
    >> document.js containing the line
    >>
    >> document.writeln("Date of document.pdf is YYYY-MM-DD")
    >>

    >[...]
    >
    >Why would you want to suggest a javascript solution that relies on
    >javascript being available *and* enabled in the end-users client, when a
    >perfectly servicable php solution (which will serve the date to the end-user
    >without the need for javascript to be available and enabled) has been
    >offered to and used by the OP? Other than this being a javascript NG of
    >course...


    The OP asked in a javascript newsgroup and was obviously considering the
    possibility of a javascript solution. Whether you like it or not, many
    Web pages do require javascript; and for those there can be no rational
    objection to using javascript a bit more.

    This is a discussion group; if I had wanted my response not to be
    available to others, I would not have posted it in News. Designers of
    professional sites would have and use PHP; but not everyone has PHP
    available or wants to learn it.

    News is not a synchronous medium; one should not presume from the
    datestamp of an article that it will have reached all other readers soon
    after.

    The technique is adaptable for other purposes.

    It's a good idea to read the newsgroup and its FAQ. See below.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Mar 4, 2007
    #17
  18. While the city slept, Dr J R Stockton ()
    feverishly typed...

    > The OP asked in a javascript newsgroup and was obviously considering
    > the possibility of a javascript solution. Whether you like it or
    > not, many Web pages do require javascript; and for those there can be
    > no rational objection to using javascript a bit more.


    I agree that many web pages do require javascript for effects that cannot be
    supplied by HTML, styling, or server-side processing. But these effects
    should not diminish the page if javascript is not available - eg, it should
    not be relied upon to provide content. I'm talking about the concept of
    "graceful degradation" here. The result that the OP was after was -- IMHO --
    best served by a server-side process, as this would have direct access to
    the file information he needed. The fact that he asked in a javascript
    newsgroup was -- again, IMHO -- because he wasn't necessarily aware that
    there would be any other way of doing it, and he had found what he thought
    would be a javascript solution which in actual fact wasn't so he asked in
    this group to see if it could be made to work.

    > This is a discussion group; if I had wanted my response not to be
    > available to others, I would not have posted it in News. Designers of
    > professional sites would have and use PHP; but not everyone has PHP
    > available or wants to learn it.


    Accepted. It is quite true that not all users of this group will have
    server-side scripting available to them (although availability of
    fuller-featured hosting is a lot cheaper these days), so your solution would
    indeed provide a suitable answer to those people. To the others I would
    recommend learning server-side scripting such as PHP in any case... as long
    as there is space on their "To-do" list of course!

    > News is not a synchronous medium; one should not presume from the
    > datestamp of an article that it will have reached all other readers
    > soon after.


    Accepted. I didn't notice the posting date/time of your message until after
    I had made my reply, and I apologise for that.

    > The technique is adaptable for other purposes.


    Indeed, as are most techniques. The beauty of the medium is that a solution
    to an otherwise unconnected issue can provide the inspiration to solve a
    separate problem of your own... of the "something like that might work for
    the problem I've been having" type.

    > It's a good idea to read the newsgroup and its FAQ. See below.


    I haven't been on this newsgroup for sometime and returned recently as I was
    trying to implement a DHTML calendar plugin that wasn't playing ball. Fun to
    be back, and to see some familiar names. Talking of names, does Jim not do
    the FAQ's any more? Seeing some guy called "Randy" is FAQEditor, although I
    see the FAQ's are still on jibbering.com.

    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"
     
    nice.guy.nige, Mar 4, 2007
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zee Zop

    MMYYYY - datestamp

    Zee Zop, Sep 20, 2004, in forum: Perl
    Replies:
    5
    Views:
    674
    Gunnar Hjalmarsson
    Oct 1, 2004
  2. Stu
    Replies:
    2
    Views:
    796
    Rob McAninch
    Apr 6, 2004
  3. Marek Kurowski
    Replies:
    1
    Views:
    999
    Mark A. Odell
    Aug 18, 2004
  4. Replies:
    3
    Views:
    158
    Michael Fesser
    Oct 28, 2004
  5. Phil M

    display datestamp in HTML

    Phil M, Mar 2, 2007, in forum: Perl Misc
    Replies:
    9
    Views:
    268
    Joe Smith
    May 18, 2007
Loading...

Share This Page