By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

Display datestamp script in HTML

P: n/a
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!
Mar 2 '07 #1
Share this Question
Share on Google+
17 Replies


P: n/a
While the city slept, Phil M (ji****@trexagi.net) 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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 2 '07 #2

P: n/a
While the city slept, nice.guy.nige (ni********@deadspam.com) 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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 2 '07 #3

P: n/a
>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.
Mar 2 '07 #4

P: n/a
the page should look someting like this (plus the datestamp I'm trying
to include)

http://www.greekradio.net/psa.html
Mar 2 '07 #5

P: n/a
While the city slept, Phil M (ji****@trexagi.net) 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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 3 '07 #6

P: n/a
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.
Mar 3 '07 #7

P: n/a
While the city slept, Phil M (ji****@trexagi.net) 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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 3 '07 #8

P: n/a
On Sat, 03 Mar 2007 17:57:07 +0100, Phil M <ji****@trexagi.netwrote:
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/
Mar 3 '07 #9

P: n/a
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
Mar 3 '07 #10

P: n/a
While the city slept, Phil M (ji****@trexagi.net) 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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 3 '07 #11

P: n/a
>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.
Mar 3 '07 #12

P: n/a
In comp.lang.javascript message <d0pgu29t0pqeinrr25g4psg18t5hbg3i37@4ax.
com>, Fri, 2 Mar 2007 12:55:24, Phil M <ji****@trexagi.netposted:
>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"></scriptin 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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 3 '07 #13

P: n/a
>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.
Mar 3 '07 #14

P: n/a
While the city slept, Dr J R Stockton (re*******@merlyn.demon.co.uk)
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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 3 '07 #15

P: n/a
While the city slept, Phil M (ji****@trexagi.net) 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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 3 '07 #16

P: n/a
In comp.lang.javascript message <45***********************@authen.yellow
..readfreenews.net>, Sat, 3 Mar 2007 21:44:44, nice.guy.nige
<ni********@deadspam.composted:
>While the city slept, Dr J R Stockton (re*******@merlyn.demon.co.uk)
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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 4 '07 #17

P: n/a
While the city slept, Dr J R Stockton (re*******@merlyn.demon.co.uk)
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. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Mar 4 '07 #18

This discussion thread is closed

Replies have been disabled for this discussion.