Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > ASP > ASP Forum > แปลงหน่วย ไบต์ เป็น เมก คือผมมี script upload (เอามาจากเว็บนี้หล่ะครับ)


 

[ASP] แปลงหน่วย ไบต์ เป็น เมก คือผมมี script upload (เอามาจากเว็บนี้หล่ะครับ)

 
Topic : 034066

Guest



คือผมมี script upload (เอามาจากเว็บนี้หล่ะครับ) แล้วผมเก็บขนาดไฟล์ลงฐานข้อมูลแต่ติดตรงที่ว่าหน่วยที่เก็บเป็นไบต์ครับ บางไฟล์ใหญ่ทำให้อ่านยากผมเลยรู้ว่าแปลงยังไงที่ต้องการ เช่น

ไฟล์ไม่ถึงเมกก็เป็น
0.78 MB

ไฟล์ร้อยเมก
988 MB

ไฟล์เกิน 1024 เมก ก็เป็น
1.82 GB
อยากได้แบบนี้ครับ



Tag : - - - -

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-11-09 11:37:04 By : เด็กน้อยหน้าแก่ View : 3007 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เขียนเงื่อนไขเอาครับ ไม่ยากครับ

ในการแปลงให้เอา Bytes * 1024 * 1024
Date : 2009-11-09 13:34:48 By : webmaster
 

 

No. 2



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์


aspSmartUpload : Sample 2
001.<%
002.Function ConvertBytes(ByRef anBytes)
003.    Dim lnSize          ' File Size To be returned
004.    Dim lsType          ' Type of measurement (Bytes, KB, MB, GB, TB)
005.     
006.    Const lnBYTE = 1
007.    Const lnKILO = 1024                     ' 2^10
008.    Const lnMEGA = 1048576                  ' 2^20
009.    Const lnGIGA = 1073741824               ' 2^30
010.    Const lnTERA = 1099511627776            ' 2^40
011.    '    Const lnPETA = 1.12589990684262E+15        ' 2^50
012.    '    Const lnEXA = 1.15292150460685E+18        ' 2^60
013.    '    Const lnZETTA = 1.18059162071741E+21    ' 2^70
014.    '    Const lnYOTTA = 1.20892581961463E+24    ' 2^80
015.     
016.    If anBytes = "" Or Not IsNumeric(anBytes) Then Exit Function
017.     
018.    If anBytes < 0 Then Exit Function  
019.'    If anBytes < lnKILO Then
020.'        ' ByteConversion
021.'        lnSize = anBytes
022.'        lsType = "bytes"
023.'    Else       
024.        If anBytes < lnMEGA Then
025.            ' KiloByte Conversion
026.            lnSize = (anBytes / lnKILO)
027.            lsType = "kb"
028.        ElseIf anBytes < lnGIGA Then
029.            ' MegaByte Conversion
030.            lnSize = (anBytes / lnMEGA)
031.            lsType = "mb"
032.        ElseIf anBytes < lnTERA Then
033.            ' GigaByte Conversion
034.            lnSize = (anBytes / lnGIGA)
035.            lsType = "gb"
036.        Else
037.            ' TeraByte Conversion
038.            lnSize = (anBytes / lnTERA)
039.            lsType = "tb"
040.        End If
041.'    End If
042.    ' Remove fraction
043.    'lnSize = CLng(lnSize)
044.    lnSize = FormatNumber(lnSize, 2, True, False, True)
045.     
046.    ' Return the results
047.    ConvertBytes = lnSize & " " & lsType
048.End Function
049.'<-----------------------จบส่วนฟังก์ชั่นที่เพิ่มเข้าไป--------------------------->
050. 
051.'  Variables
052.'  *********
053.   Dim mySmartUpload
054.   Dim file
055.   Dim intCount
056.   intCount=0
057.         
058.'  Object creation
059.'  ***************
060.   Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
061. 
062.'  Upload
063.'  ******
064.   mySmartUpload.Upload
065. 
066.'  Select each file
067.'  ****************
068.   For each file In mySmartUpload.Files
069.   '  Only if the file exist
070.   '  **********************
071.      If not file.IsMissing Then
072.      '  Save the files with his original names in a virtual path of the web server
073.      '  ****************************************************************************
074.         file.SaveAs(Server.MapPath("Upload/" & file.FileName))
075.         ' sample with a physical path
076.         ' file.SaveAs("c:\temp\" & file.FileName)
077.        Size1 = ConvertBytes(file.Size) '<------ สั่งให้คำนวน
078.      '  Display the properties of the current file
079.      '  ******************************************
080.         Response.Write("Name = " & file.Name & "<BR>")
081.         Response.Write("Size = " & Size1 & "<BR>") '<------ แสดงขนาดที่คำนวนแล้ว
082.         Response.Write("FileName = " & file.FileName & "<BR>")
083.         Response.Write("FileExt = " & file.FileExt & "<BR>")
084.         Response.Write("FilePathName = " & file.FilePathName & "<BR>")
085.         Response.Write("ContentType = " & file.ContentType & "<BR>")
086.         Response.Write("ContentDisp = " & file.ContentDisp & "<BR>")
087.         Response.Write("TypeMIME = " & file.TypeMIME & "<BR>")
088.         Response.Write("SubTypeMIME = " & file.SubTypeMIME & "<BR>")
089.         intCount = intCount + 1
090.      End If
091.   Next
092. 
093.'  Display the number of files which could be uploaded
094.'  ***************************************************
095.   Response.Write("<BR>" & mySmartUpload.Files.Count & " files could be uploaded.<BR>")
096. 
097.'  Display the number of files uploaded
098.'  ************************************
099.   Response.Write(intCount & " file(s) uploaded.<BR>")
100.%>


ผมลองกับ aspSmartUpload Sample 2 แล้วได้ผลครับ แปลงได้ทั้ง kb mk gb tb ครับ จากนั้นค่อยเอาไปจัดการลงฐานข้อมูลเองนะครับคงไม่ยากแล้ว
Date : 2009-11-09 22:53:36 By : asptuy
 

 

No. 3



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์


พิมพ์ผิด mb ไม่ใช่ mk คิดไปได้ตรูสงสัยหิว
Date : 2009-11-09 22:55:47 By : asptuy
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : แปลงหน่วย ไบต์ เป็น เมก คือผมมี script upload (เอามาจากเว็บนี้หล่ะครับ)
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่