Results 1 to 2 of 2

Thread: validating a file before you save it on the server

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Posts
    89
    Hi all im giving my user the right to post pictures on my site. I am using asp upload. THe problem i am having is validating the pictures, i figured i could do that by checking the last 3 characters and if its a jpg or gif then it could be posted otherwise they get the boot. The problem is the upload component is flacky and posts things anyway.

    Here is my code to for the first page with the file form field on it.

    test.asp-
    <!-- Upload form containing text as well as file items -->

    <HTML>
    <!-- Hide script from older browsers


    <BODY BGCOLOR="#FFFFFF">

    <h2>Add a Picture</h2>
    <%session("strTextField")=Request.Form("DESCR1")%>
    <%session("strTextField")=Request.Form("DESCR2")%>

    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="UploadScript.asp" name="frmName">
    File 1:</TD>
    <TD><INPUT TYPE=FILE NAME="FILE1">
    Description 1:<INPUT TYPE=TEXT NAME="DESCR1"><BR>

    File 2:<INPUT TYPE=FILE NAME="FILE2">
    Description 2:<INPUT TYPE=TEXT NAME="DESCR2"><BR>
    <INPUT TYPE=SUBMIT VALUE="Upload!">
    </FORM>


    </BODY>
    </HTML>

    here is the uploadscript.asp

    <HTML>
    <BODY BGCOLOR="#FFFFFF">


    <%



    Function GetFileName(FileName)
    'Parses the filename out of a directory string

    Dim i



    For i = Len(FileName) To 1 Step -1
    If Mid(FileName, i, 1) = "\" then

    Exit For
    End If
    Next

    GetFileName = Mid(FileName, i + 1)

    End Function






    Function strRightPart(strInput, chrMostRight)

    Dim chrMostRight_tmp
    Dim nChr, j, Count, chrPlace

    nChr = Len(strInput)

    For j = nChr To 1 Step -1
    chrMostRight_tmp = Left(strInput, j)
    If Right(chrMostRight_tmp, 1) = chrMostRight Then Exit For
    Count = Count + 1
    Next

    chrPlace = nChr - (Count - 1)
    strRightPart = Mid(strInput, chrPlace)

    End Function

    'Set Upload = Server.CreateObject("Persits.Upload.1")
    'Upload.SaveVirtual("/upload")
    'cgi-bin/pictures/picts

    'set up the loop


    if request.form("DESCR1")<>"" then
    ext=Right(request.form("DESCR1"), 3)
    If Ext = "GIF" or Ext = "JPG" or Ext = "BMP" or Ext = "gif" or Ext = "jpg" or Ext = "bmp" Then
    Response.Write File.ImageWidth & " x " & File.ImageHeight & "</TD></TR>"
    Else
    errormessage=GetFileName(file.path) & "was not saved because it is not a file"
    End If
    end if
    if len(errormessage)=0 then

    Set Upload = Server.CreateObject("Persits.Upload.1")
    Upload.SaveVirtual("/upload")


    For Each File in Upload.Files

    response.write(file.path & "<br>")
    'fileP=file.path
    'response.write(extractfilename & "<BR>")
    'strfileName=Response.Write(file.path & extractfilename)
    'Response.Write(file.path & extractfilename)
    'Response.Write file.ExtractFileName(File.Path)
    Response.Write File.ImageWidth & " x " & File.ImageHeight & "<br>"




    'save picture name in db here



    set my_conn= Server.CreateObject("ADODB.Connection")
    my_Conn.Open ConnString


    Set rs = Server.CreateObject("adodb.recordset")
    rs.Open "Image", ConnString

    strSQL=


    my_Conn.Execute strSQL
    response.write strsql
    response.write errormessage

    Next
    else
    response.write errormessage
    end if
    %>




    Files:<BR>






    </BODY>
    <% my_conn.close
    my_conn=nothing%>
    </HTML>


    everytime i try to validate i get an error message from the component. im afraid to release this unitl i can make sure i am only geting pictures.

    thanks in advance

    Scott

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425
    Maybe you can use objFile.Type to check what information you can get from the file?
    "Experience is something you don't get until just after you need it."

Posting Permissions

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



Click Here to Expand Forum to Full Width