Forum Moderators: open

Message Too Old, No Replies

File size info with link

how to automatically determine file size and display it near link

         

KeithDouglas

4:02 pm on May 5, 2004 (gmt 0)

10+ Year Member



I work with a website that has lots of links of the type:


Title: Blah blah blah - current ([url=http://#]Abstract[/url]) ([url=http://#]Excerpt[/url]) ([url=http://#]Complete article in PDF[/url] 250K)

Title: Blah blah blah - April ([url=http://#]Abstract[/url]) ([url=http://#]Excerpt[/url]) ([url=http://#]Complete article in PDF[/url] 180K)

A decision was made a long time ago to provide the file size, "265K" or whatever, for large PDF files. It's problematic to continually update these filesize numbers.

There are many pages where the link URL stays the same, but the file it links to is updated regularly ( and the filesize can change dramatically for each update). And sometimes there are many links on different pages all to this same file, so when one new file is loaded to the 'site there are a half dozen places where the file size info needs to be changed.

Is there any kind of code or script that can be placed where the filesize number goes that will automatically look at the file on the server and figure out how large the file is and then write that number on the HTML page?

Thanks!

txbakers

4:18 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do this by entering all the information in a database, and building the page dynamically.

That way you only have to maintain the DB file, and not worry about updating the web page.

DrDoc

4:22 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also have PHP/Perl/ASP check the file size. In PHP this is done by calling filesize(). In Perl you call stat().

HelenDev

4:24 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there any kind of code or script that can be placed where the filesize number goes that will automatically look at the file on the server and figure out how large the file is and then write that number on the HTML page?

You know, I think there is. I've got a feeling I came across an asp script for doing this a while back. If you've got asp capability I can see if I can dig it up from somewhere. Alternatively I think you can also do it with PHP.

sonjay

2:09 am on May 6, 2004 (gmt 0)

10+ Year Member



You can also do this with server-side includes, if you can have those pages parsed for includes:

File size: <!--#fsize file="path/to/filename.pdf" -->

Krapulator

2:51 am on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in ASP:

dim obj, theFile, FileSize

set obj = Server.CreateObject("Scripting.FileSystemObject")
set theFile = obj.GetFile("c:\pdffile.pdf")
FileSize = theFile.Size
set theFile = nothing
set obj = nothing

Response.write "Filesize is " & FileSize & " Bytes"

will1480

2:54 am on May 6, 2004 (gmt 0)

10+ Year Member



If you are doing frequent changes then I would sugest dynamically creating your pages. But if it is work that can be done by a monkey...then pay a monkey to do it ( i hear they work for banannas :) ). Redesigning your website might be costly, especially if you dont have the resources. Evaluate the cost/benefit.