display datestamp in HTML

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

  1. Phil M

    Phil M Guest

    Hi all. I have am HTML web page where I upload a 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 perl scripts (in .pl) 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. Assume I find a
    pl script which captures the datestamp of document.pdf, all I know is
    that I have to modify the header of the .pl file to read:
    #!/usr/bin/perl then upload it in /bin

    THEN, what code do I have to paste in the index.html to print the
    actual datestamp? The server is Apache 1.3.26

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

  2. Phil M

    Tony Curtis Guest

    Phil M wrote:
    > Hi all. I have am HTML web page where I upload a 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?


    If the modification date of the file is what you want as the actual
    document modification date, then SSI would be a much simpler solution,
    but nothing to do with perl.

    hth
    t
     
    Tony Curtis, Mar 2, 2007
    #2
    1. Advertising

  3. Phil M

    Phil M Guest

    Thanks for the quick reply. It can be either. Modification date,
    upload date or file date or creation date; whatever is simpler.

    Either the file datestamp (as it appears next to the filename when I
    log in to the ftp web server) or the date which it was uploaded. it
    doesn't matter since the date that I create the pdf file I also upload
    it; so creation/modification/upload date is the same.

    >If the modification date of the file is what you want as the actual
    >document modification date, then SSI would be a much simpler solution,
    >but nothing to do with perl.
     
    Phil M, Mar 2, 2007
    #3
  4. Phil M

    Phil M Guest

    > then SSI would be a much simpler solution

    Thanks, I'll ask the same question on a SSI Javascript group.
     
    Phil M, Mar 2, 2007
    #4
  5. Phil M

    Phil M Guest

    I found a small perl script which claims to do the trick and it seems
    that I can't get the code right:

    Here's my web page: (note that the date doesn't appear)
    http://www.greekradio.net/psa.html

    This is the script: (stored in cgi/lastmodified.pl)


    #!/usr/bin/perl

    # Script name:
    # @1 Last Modified Date and Time

    # Purpose:
    # This Perl script checks the "Last Modified" date and time
    # of a file.

    # Uses:
    # Call the display via SSI using the tag below:
    # <!--#include virtual="yourfolder1/yourfolder2/lastmodified.cgi" -->

    # License Notice:
    # Copyright 2004 UPDI Network Enterprise, www.upoint.info/cgi
    # You are free to use and distribute this script as long as
    # you keep this license notice intact.

    ############################################################
    # FULL PATH (not URL) to the file:
    ############################################################
    $filename = "/hrnet/u/chrb/www/ekm_psa/document.pdf";

    ############################################################
    # Turn on debug mode so that you can see the formats
    ############################################################
    $debug = "0"; # 1 = ON 0 = OFF
    # Set to "0" after testing
    ############################################################
    # DO NOT EDIT BELOW THIS LINE
    ############################################################

    use POSIX 'strftime';
    my $time = (stat $filename)[9];
    print "Content-type: text/html\n\n";

    print strftime '%a %d.%b.%Y @ %I:%M %p', localtime $time;

    if ($debug eq 1){
    print "<p>";
    print "a - ";
    print strftime '%a', localtime $time;
    print "<BR>";
    print "A - ";
    print strftime '%A', localtime $time;
    print "<BR>";
    print "b - ";
    print strftime '%b', localtime $time;
    print "<BR>";
    print "B - ";
    print strftime '%B', localtime $time;
    print "<BR>";
    print "c - ";
    print strftime '%c', localtime $time;
    print "<BR>";
    print "d - ";
    print strftime '%d', localtime $time;
    print "<BR>";
    print "H - ";
    print strftime '%H', localtime $time;
    print "<BR>";
    print "I - ";
    print strftime '%I', localtime $time;
    print "<BR>";
    print "j - ";
    print strftime '%j', localtime $time;
    print "<BR>";
    print "m - ";
    print strftime '%m', localtime $time;
    print "<BR>";
    print "M - ";
    print strftime '%M', localtime $time;
    print "<BR>";
    print "p - ";
    print strftime '%p', localtime $time;
    print "<BR>";
    print "s - ";
    print strftime '%s', localtime $time;
    print "<BR>";
    print "U - ";
    print strftime '%U', localtime $time;
    print "<BR>";
    print "w - ";
    print strftime '%w', localtime $time;
    print "<BR>";
    print "W - ";
    print strftime '%W', localtime $time;
    print "<BR>";
    print "x - ";
    print strftime '%x', localtime $time;
    print "<BR>";
    print "X - ";
    print strftime '%X', localtime $time;
    print "<BR>";
    print "y - ";
    print strftime '%y', localtime $time;
    print "<BR>";
    print "Y - ";
    print strftime '%Y', localtime $time;
    print "<BR>";
    print "Z - ";
    print strftime '%Z', localtime $time;
    }

    Thanks for any suggestions on what I might be doing wrong.
     
    Phil M, Mar 2, 2007
    #5
  6. Phil M

    Phil M Guest

    Phil M, Mar 2, 2007
    #6
  7. Phil M

    Mumia W. Guest

    On 03/02/2007 10:40 AM, Phil M wrote:
    > Hi all. I have am HTML web page where I upload a 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
    > [...]


    This is how you might find out the datestamp:

    use POSIX qw(asctime);
    my $filename = 'my.flat';
    print asctime(localtime((stat $filename)[9]));

    Read the documentation for asctime and stat. I'm assuming that you're a
    Windows user:

    Start->Run->"perldoc POSIX"
    Start->Run->"perldoc -f stat"

    After you have the datestamp in a string, printing it should be
    elementary. Good luck.
     
    Mumia W., Mar 2, 2007
    #7
  8. Phil M

    -berlin.de Guest

    Phil M <> wrote in comp.lang.perl.misc:
    > I found a small perl script which claims to do the trick and it seems
    > that I can't get the code right:


    Then show your code. We can't help you with what we don't get to see.

    > Here's my web page: (note that the date doesn't appear)
    > http://www.greekradio.net/psa.html


    How about saying *where* the date is supposed to appear?

    > This is the script: (stored in cgi/lastmodified.pl)
    >
    > #!/usr/bin/perl
    >
    > # Script name:
    > # @1 Last Modified Date and Time
    >
    > # Purpose:
    > # This Perl script checks the "Last Modified" date and time
    > # of a file.
    >
    > # Uses:
    > # Call the display via SSI using the tag below:
    > # <!--#include virtual="yourfolder1/yourfolder2/lastmodified.cgi" -->
    >
    > # License Notice:
    > # Copyright 2004 UPDI Network Enterprise, www.upoint.info/cgi
    > # You are free to use and distribute this script as long as
    > # you keep this license notice intact.
    >
    > ############################################################
    > # FULL PATH (not URL) to the file:
    > ############################################################
    > $filename = "/hrnet/u/chrb/www/ekm_psa/document.pdf";
    >
    > ############################################################
    > # Turn on debug mode so that you can see the formats
    > ############################################################
    > $debug = "0"; # 1 = ON 0 = OFF
    > # Set to "0" after testing
    > ############################################################
    > # DO NOT EDIT BELOW THIS LINE
    > ############################################################
    >
    > use POSIX 'strftime';
    > my $time = (stat $filename)[9];
    > print "Content-type: text/html\n\n";
    >
    > print strftime '%a %d.%b.%Y @ %I:%M %p', localtime $time;
    >
    > if ($debug eq 1){
    > print "<p>";
    > print "a - ";
    > print strftime '%a', localtime $time;
    > print "<BR>";
    > print "A - ";
    > print strftime '%A', localtime $time;
    > print "<BR>";
    > print "b - ";
    > print strftime '%b', localtime $time;
    > print "<BR>";
    > print "B - ";
    > print strftime '%B', localtime $time;
    > print "<BR>";
    > print "c - ";
    > print strftime '%c', localtime $time;
    > print "<BR>";
    > print "d - ";
    > print strftime '%d', localtime $time;
    > print "<BR>";
    > print "H - ";
    > print strftime '%H', localtime $time;
    > print "<BR>";
    > print "I - ";
    > print strftime '%I', localtime $time;
    > print "<BR>";
    > print "j - ";
    > print strftime '%j', localtime $time;
    > print "<BR>";
    > print "m - ";
    > print strftime '%m', localtime $time;
    > print "<BR>";
    > print "M - ";
    > print strftime '%M', localtime $time;
    > print "<BR>";
    > print "p - ";
    > print strftime '%p', localtime $time;
    > print "<BR>";
    > print "s - ";
    > print strftime '%s', localtime $time;
    > print "<BR>";
    > print "U - ";
    > print strftime '%U', localtime $time;
    > print "<BR>";
    > print "w - ";
    > print strftime '%w', localtime $time;
    > print "<BR>";
    > print "W - ";
    > print strftime '%W', localtime $time;
    > print "<BR>";
    > print "x - ";
    > print strftime '%x', localtime $time;
    > print "<BR>";
    > print "X - ";
    > print strftime '%X', localtime $time;
    > print "<BR>";
    > print "y - ";
    > print strftime '%y', localtime $time;
    > print "<BR>";
    > print "Y - ";
    > print strftime '%Y', localtime $time;
    > print "<BR>";
    > print "Z - ";
    > print strftime '%Z', localtime $time;
    > }


    Which garbage dump did you search to find this "script"? The author
    doesn't have the slightest idea about programming, let alone Perl.
    Programming is, among other things, about letting the computer do
    the work.

    Stripped of its pompous commentary and its pathetically repetitious
    code, replace the whole thing by this:

    #!/usr/bin/perl
    use strict; use warnings;
    use POSIX 'strftime';

    my $filename = "/hrnet/u/chrb/www/ekm_psa/document.pdf";

    my $debug = 1;
    my $time = (stat $filename)[9] or die "Can't stat '$filename': $!";

    print "Content-type: text/html\n\n";

    print strftime '%a %d.%b.%Y @ %I:%M %p', localtime $time;

    if ( $debug ) {
    my $fmt = '<p>' . join '<BR>', map "$_ - %$_",
    qw( a A b B c d H I j m p s U w W x X y Y Z);
    print strftime $fmt, localtime $time;
    }
    __END__

    > Thanks for any suggestions on what I might be doing wrong.


    You're not showing what you're doing. How can we say what you're doing
    wrong?

    Anno
     
    -berlin.de, Mar 3, 2007
    #8
  9. Phil M

    Phil M Guest

    >Stripped of its pompous commentary and its pathetically repetitious
    >code, replace the whole thing by this:


    Anno,

    YOUR CODE WORKED! here:
    http://s135598769.onlinehome.us/greekradio/psa.shtml

    However, I had to rename the file with a .shtml to work. Is there any
    way to keep the .html extension?

    Also, you may want to make this small and very efficient code
    available somewhere 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. Good work!

    Please inform for the .shtml issue.

    Thanks again.
     
    Phil M, Mar 3, 2007
    #9
  10. Phil M

    Joe Smith Guest

    Phil M wrote:

    > However, I had to rename the file with a .shtml to work. Is there any
    > way to keep the .html extension?


    You'll have to ask the person who controls the configuration file for
    the web server. If they don't allow individual .htaccess files, the
    answer is "no".
    -Joe
     
    Joe Smith, May 18, 2007
    #10
    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:
    687
    Gunnar Hjalmarsson
    Oct 1, 2004
  2. Joey
    Replies:
    0
    Views:
    993
  3. Stu
    Replies:
    2
    Views:
    824
    Rob McAninch
    Apr 6, 2004
  4. Marek Kurowski
    Replies:
    1
    Views:
    1,036
    Mark A. Odell
    Aug 18, 2004
  5. Phil M

    Display datestamp script in HTML

    Phil M, Mar 2, 2007, in forum: Javascript
    Replies:
    17
    Views:
    313
    nice.guy.nige
    Mar 4, 2007
Loading...

Share This Page