|
|
|
แปลงหน่วย ไบต์ เป็น เมก คือผมมี script upload (เอามาจากเว็บนี้หล่ะครับ) |
|
|
|
|
|
|
|
เขียนเงื่อนไขเอาครับ ไม่ยากครับ
ในการแปลงให้เอา Bytes * 1024 * 1024
|
|
|
|
|
Date :
2009-11-09 13:34:48 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aspSmartUpload : Sample 2
<%
Function ConvertBytes(ByRef anBytes)
Dim lnSize ' File Size To be returned
Dim lsType ' Type of measurement (Bytes, KB, MB, GB, TB)
Const lnBYTE = 1
Const lnKILO = 1024 ' 2^10
Const lnMEGA = 1048576 ' 2^20
Const lnGIGA = 1073741824 ' 2^30
Const lnTERA = 1099511627776 ' 2^40
' Const lnPETA = 1.12589990684262E+15 ' 2^50
' Const lnEXA = 1.15292150460685E+18 ' 2^60
' Const lnZETTA = 1.18059162071741E+21 ' 2^70
' Const lnYOTTA = 1.20892581961463E+24 ' 2^80
If anBytes = "" Or Not IsNumeric(anBytes) Then Exit Function
If anBytes < 0 Then Exit Function
' If anBytes < lnKILO Then
' ' ByteConversion
' lnSize = anBytes
' lsType = "bytes"
' Else
If anBytes < lnMEGA Then
' KiloByte Conversion
lnSize = (anBytes / lnKILO)
lsType = "kb"
ElseIf anBytes < lnGIGA Then
' MegaByte Conversion
lnSize = (anBytes / lnMEGA)
lsType = "mb"
ElseIf anBytes < lnTERA Then
' GigaByte Conversion
lnSize = (anBytes / lnGIGA)
lsType = "gb"
Else
' TeraByte Conversion
lnSize = (anBytes / lnTERA)
lsType = "tb"
End If
' End If
' Remove fraction
'lnSize = CLng(lnSize)
lnSize = FormatNumber(lnSize, 2, True, False, True)
' Return the results
ConvertBytes = lnSize & " " & lsType
End Function
'<-----------------------จบส่วนฟังก์ชั่นที่เพิ่มเข้าไป--------------------------->
' Variables
' *********
Dim mySmartUpload
Dim file
Dim intCount
intCount=0
' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Upload
' ******
mySmartUpload.Upload
' Select each file
' ****************
For each file In mySmartUpload.Files
' Only if the file exist
' **********************
If not file.IsMissing Then
' Save the files with his original names in a virtual path of the web server
' ****************************************************************************
file.SaveAs(Server.MapPath("Upload/" & file.FileName))
' sample with a physical path
' file.SaveAs("c:\temp\" & file.FileName)
Size1 = ConvertBytes(file.Size) '<------ สั่งให้คำนวน
' Display the properties of the current file
' ******************************************
Response.Write("Name = " & file.Name & "<BR>")
Response.Write("Size = " & Size1 & "<BR>") '<------ แสดงขนาดที่คำนวนแล้ว
Response.Write("FileName = " & file.FileName & "<BR>")
Response.Write("FileExt = " & file.FileExt & "<BR>")
Response.Write("FilePathName = " & file.FilePathName & "<BR>")
Response.Write("ContentType = " & file.ContentType & "<BR>")
Response.Write("ContentDisp = " & file.ContentDisp & "<BR>")
Response.Write("TypeMIME = " & file.TypeMIME & "<BR>")
Response.Write("SubTypeMIME = " & file.SubTypeMIME & "<BR>")
intCount = intCount + 1
End If
Next
' Display the number of files which could be uploaded
' ***************************************************
Response.Write("<BR>" & mySmartUpload.Files.Count & " files could be uploaded.<BR>")
' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(s) uploaded.<BR>")
%>
ผมลองกับ aspSmartUpload Sample 2 แล้วได้ผลครับ แปลงได้ทั้ง kb mk gb tb ครับ จากนั้นค่อยเอาไปจัดการลงฐานข้อมูลเองนะครับคงไม่ยากแล้ว
|
|
|
|
|
Date :
2009-11-09 22:53:36 |
By :
asptuy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พิมพ์ผิด mb ไม่ใช่ mk คิดไปได้ตรูสงสัยหิว
|
|
|
|
|
Date :
2009-11-09 22:55:47 |
By :
asptuy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|