Pure ASP Upload 2 Support Product Page

This topic is locked
This topic was archived

Downloading File properties

Posted 02 Oct 2001 13:50:40
1
has voted
02 Oct 2001 13:50:40 Christian Adams posted:
I bought this extension and its excellent BUT
I want to download the files which I have uploaded BUT
HOW do I show the file Size before downloading so that
I can get an estimated download time.
HELP



Replies

Replied 04 Oct 2001 19:11:33
04 Oct 2001 19:11:33 George Petrov replied:
Here is a small script I use - change the "downloads" path before usage.

<pre id=code><font face=courier size=2 id=code>
&lt;%
Function getFileSize(filename)
filespec = "/downloads/" & filename
filespec = Server.MapPath(filespec)
Set fso = CreateObject("Scripting.FileSystemObject"
on error resume next
Set f = fso.GetFile(filespec)
if err.number &lt;&gt; 0 then
getFileSize = "0 KB"
else
fSize = round(f.size / 1024,0)
if fSize &gt; 1024 then
getFileSize = round(fSize / 1024,2) & " MB"
else
getFileSize = fSize & " KB"
end if
end if
on error goto 0
End Function
%&gt;
</font id=code></pre id=code>

then you can use it as:

<pre id=code><font face=courier size=2 id=code>
Size of: &lt;%=myRecordset.Fields.Item("filename".Value%&gt; = &lt;%=getFileSize(myRecordset.Fields.Item("filename".Value)%&gt;
</font id=code></pre id=code>

---------------------------------------
George Petrov - CTO, www.UDzone.com

www.UDzone.com : A Dreamweaver,
Dreamweaver Ultradev and Fireworks site
by developers for developers.
---------------------------------------

Replied 07 Oct 2001 07:25:43
07 Oct 2001 07:25:43 Jack Neary replied:
Thanks George... That fit the bill and I didn't even have to ask anything. <img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>

Edited by - jnear on 10/07/2001 09:54:44
Replied 27 Jun 2005 21:11:27
27 Jun 2005 21:11:27 Daniel Arce replied:
PLease help,

Here is my code for the file size retrieve. If I modify your funciton code to a specific file rather that use the mappath method I get the fize size. But I can't get it to read the url of the file in the field where the url is stored. This is the out put of the page:

calendar.mxp = 0 KB


The file url comes out of the field &lt;%=(rsFiles.Fields.Item("FileUrl".Value)%&gt; but the &lt;%=getFileSize(rsFiles.Fields.Item("FileUrl".Value)%&gt; does not return the file size.

Here is the page with your function:


&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;!--#include file="../../../Connections/vegaCMS.asp" --&gt;

&lt;!-- File Size function to display the file size of files --&gt;
&lt;%
Function getFileSize(filename)
filespec = "/uploads/" & filename
filespec = Server.MapPath(filespec)
Set fso = CreateObject("Scripting.FileSystemObject"
on error resume next
Set f = fso.GetFile(filespec)
if err.number &lt;&gt; 0 then
getFileSize = "0 KB"
else
fSize = round(f.size / 1024,0)
if fSize &gt; 1024 then
getFileSize = round(fSize / 1024,2) & " MB"
else
getFileSize = fSize & " KB"
end if
end if
on error goto 0
End Function
%&gt;
&lt;!-- End File Size Code --&gt;

&lt;%
Dim rsFiles
Dim rsFiles_numRows

Set rsFiles = Server.CreateObject("ADODB.Recordset"
rsFiles.ActiveConnection = MM_vegaCMS_STRING
rsFiles.Source = "SELECT * FROM files"
rsFiles.CursorType = 0
rsFiles.CursorLocation = 2
rsFiles.LockType = 1
rsFiles.Open()

rsFiles_numRows = 0
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;%=(rsFiles.Fields.Item("FileUrl".Value)%&gt;
= &lt;%=getFileSize(rsFiles.Fields.Item("FileUrl".Value)%&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
&lt;%
rsFiles.Close()
Set rsFiles = Nothing
%&gt;






Reply to this topic