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>
<%
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 <> 0 then
getFileSize = "0 KB"
else
fSize = round(f.size / 1024,0)
if fSize > 1024 then
getFileSize = round(fSize / 1024,2) & " MB"
else
getFileSize = fSize & " KB"
end if
end if
on error goto 0
End Function
%>
</font id=code></pre id=code>
then you can use it as:
<pre id=code><font face=courier size=2 id=code>
Size of: <%=myRecordset.Fields.Item("filename".Value%> = <%=getFileSize(myRecordset.Fields.Item("filename".Value)%>
</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.
---------------------------------------
<pre id=code><font face=courier size=2 id=code>
<%
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 <> 0 then
getFileSize = "0 KB"
else
fSize = round(f.size / 1024,0)
if fSize > 1024 then
getFileSize = round(fSize / 1024,2) & " MB"
else
getFileSize = fSize & " KB"
end if
end if
on error goto 0
End Function
%>
</font id=code></pre id=code>
then you can use it as:
<pre id=code><font face=courier size=2 id=code>
Size of: <%=myRecordset.Fields.Item("filename".Value%> = <%=getFileSize(myRecordset.Fields.Item("filename".Value)%>
</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
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 <%=(rsFiles.Fields.Item("FileUrl".Value)%> but the <%=getFileSize(rsFiles.Fields.Item("FileUrl".Value)%> does not return the file size.
Here is the page with your function:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../../Connections/vegaCMS.asp" -->
<!-- File Size function to display the file size of files -->
<%
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 <> 0 then
getFileSize = "0 KB"
else
fSize = round(f.size / 1024,0)
if fSize > 1024 then
getFileSize = round(fSize / 1024,2) & " MB"
else
getFileSize = fSize & " KB"
end if
end if
on error goto 0
End Function
%>
<!-- End File Size Code -->
<%
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
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<%=(rsFiles.Fields.Item("FileUrl".Value)%>
= <%=getFileSize(rsFiles.Fields.Item("FileUrl".Value)%>
<p> </p>
<p> </p>
</body>
</html>
<%
rsFiles.Close()
Set rsFiles = Nothing
%>
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 <%=(rsFiles.Fields.Item("FileUrl".Value)%> but the <%=getFileSize(rsFiles.Fields.Item("FileUrl".Value)%> does not return the file size.
Here is the page with your function:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../../Connections/vegaCMS.asp" -->
<!-- File Size function to display the file size of files -->
<%
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 <> 0 then
getFileSize = "0 KB"
else
fSize = round(f.size / 1024,0)
if fSize > 1024 then
getFileSize = round(fSize / 1024,2) & " MB"
else
getFileSize = fSize & " KB"
end if
end if
on error goto 0
End Function
%>
<!-- End File Size Code -->
<%
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
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<%=(rsFiles.Fields.Item("FileUrl".Value)%>
= <%=getFileSize(rsFiles.Fields.Item("FileUrl".Value)%>
<p> </p>
<p> </p>
</body>
</html>
<%
rsFiles.Close()
Set rsFiles = Nothing
%>