Display datestamp script in HTML

P

Phil M

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!
 
N

nice.guy.nige

While the city slept, Phil M ([email protected]) 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
 
N

nice.guy.nige

While the city slept, nice.guy.nige ([email protected]) 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
 
D

Dr J R Stockton

In comp.lang.javascript message <d0pgu29t0pqeinrr25g4psg18t5hbg3i37@4ax.
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.
 
P

Phil M

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.
 
O

OmegaJunior

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.
 
P

Phil M

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.
 
N

nice.guy.nige

While the city slept, Dr J R Stockton ([email protected])
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
 
N

nice.guy.nige

While the city slept, Phil M ([email protected]) feverishly typed...
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
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
..readfreenews.net>, Sat, 3 Mar 2007 21:44:44, nice.guy.nige
While the city slept, Dr J R Stockton ([email protected])
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.
 
N

nice.guy.nige

While the city slept, Dr J R Stockton ([email protected])
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top