Linked file properties

S

SmilingPolitely

I would like to have the properties of a linked file appear on the page
linking to it, so that the user can see the date last modified and file
size.

I.E.

<a href="filename>Click here to download file: size <script to insert
file size>, last modified on <script to insert date last modified></a>

Is this possible using only javascript. I don't have access to
PHP/ASP/anything else useful on the server. Perhaps you might know of
an alternate way to achieve my aims?

Any help is appreciated.
 
M

Martin Honnen

SmilingPolitely wrote:

<a href="filename>Click here to download file: size <script to insert
file size>, last modified on <script to insert date last modified></a>

Is this possible using only javascript. I don't have access to
PHP/ASP/anything else useful on the server. Perhaps you might know of
an alternate way to achieve my aims?

It is certainly possible using JavaScript on the server. If you do not
have server-side scripting available then if you consider those infos
important for your users you have to insert them by hand in the markup.
If the infos are optional you could consider using client-side script to
make HTTP HEAD requests and try to read out the info from the HTTP
response headers:
<http://home.arcor.de/martin.honnen/javascript/200504/test2005041101.html>

Note that the example is meant to be a proof of concept, I have tested
that it works with Mozilla and with IE on Windows but I know that at
least current beta releases of Opera have some support for
XMLHttpRequest but do not support methods to get the response headers.
And I think others have reported that some Safari versions do not
support HTTP HEAD requests.
So the code in the example would need to be improved to prevent or to at
least handle errors occuring in those browsers.
 
S

SmilingPolitely

Martin said:
SmilingPolitely wrote:




It is certainly possible using JavaScript on the server. If you do not
have server-side scripting available then if you consider those infos
important for your users you have to insert them by hand in the markup.
If the infos are optional you could consider using client-side script to
make HTTP HEAD requests and try to read out the info from the HTTP
response headers:
<http://home.arcor.de/martin.honnen/javascript/200504/test2005041101.html>

Note that the example is meant to be a proof of concept, I have tested
that it works with Mozilla and with IE on Windows but I know that at
least current beta releases of Opera have some support for
XMLHttpRequest but do not support methods to get the response headers.
And I think others have reported that some Safari versions do not
support HTTP HEAD requests.
So the code in the example would need to be improved to prevent or to at
least handle errors occuring in those browsers.
Thanks very much Martin.... works like a charm
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top