www.webdeveloper.com
Results 1 to 2 of 2

Thread: check filesize

  1. #1
    Join Date
    Dec 2010
    Posts
    130

    check filesize

    Hi, im trying to check the file size for http upload.
    The upload is working fine but im having some dificulties with the filesize check, i belive theres no way to check that before the upload so i was doing something like this.

    HTML Code:
    Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
    Set MyFile = ScriptObject.CreateTextFile(pasta & nome_ficheiro)
    For i = 1 to LenB(ficheiro)
    MyFile.Write chr(AscB(MidB(ficheiro,i,1)))
    
    Next
    
    'intMaxFileSize = 102400
    response.write "1<br>"
    
    Response.Write(MyFile.Path)
    
    Response.Write(MyFile.Size)
    
    If MyFile.Size > 102400 Then
    response.write "<br>2"
    response.write "&MyFile.Size&"
    ScriptObject.DeleteFile(pasta & nome_ficheiro)
    response.Write("<script>alert('File too big, Please upload image up to 100kb!');location.href='javascript:history.go(-1)'</script>")
    Else
    But i only i only get the response.write "1".

    This is not ideal after all it allow the upload and only than do the check.

    Can anyone see whats wrong with this script or if theres a way to check the filesize before upload?

    thanks

  2. #2
    Join Date
    Dec 2010
    Posts
    130
    Clean Code

    Code:
    if ficheiro <> "" then
    Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
    Set MyFile = ScriptObject.CreateTextFile(pasta & nome_ficheiro)
    For i = 1 to LenB(ficheiro)
    MyFile.Write chr(AscB(MidB(ficheiro,i,1)))
    Next
    set f=ScriptObject.GetFile(pasta & nome_ficheiro)
    If f.Size > 102400 Then
    ScriptObject.DeleteFile(pasta & nome_ficheiro)
    response.Write("<script>alert('File too big, Please upload image up to 100kb!');location.href='javascript:history.go(-1)'</script>")
    Else
    end if
    
    MyFile.Close
    f.Close
    ScriptObject.Close
    
    end if
    Last edited by razstec; 03-05-2012 at 10:35 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles