Avatar billede marie14 Nybegynder
22. oktober 2005 - 00:03 Der er 3 kommentarer

Formular m. upload image

Jeg vil have min formular til, at uploade images sammen med de øvrige bruger oplysninger.
Lige nu har jeg 2 scripts der fungerer hver for sig og dem vil jeg gerne kombinere. Er der nogen der kan hjælpe?
Avatar billede ttopholm Nybegynder
22. oktober 2005 - 00:07 #1
Må vi se de scripts du har ....
Avatar billede stigdk Nybegynder
23. oktober 2005 - 10:50 #2
Ja det kan jeg sikkert nok, hvilket komponent bruger du?
Avatar billede marie14 Nybegynder
23. oktober 2005 - 13:07 #3
Her er mine scripts. Jeg bruger et script til upload, der ikke kræver en komponenet.
upload image filen:
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"
response.buffer = true
Response.Clear

key = request.querystring("key")

If key = "1" then
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest(RequestBin)
contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("blob").Item("Value")
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = ScriptObject.CreateTextFile(Server.MapPath("imageup/" & FileName))
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close 
Sub BuildUploadRequest(RequestBin)
  PosBeg = 1
  PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
  boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
  boundaryPos = InstrB(1,RequestBin,boundary)
  Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
  Dim UploadControl
  Set UploadControl = CreateObject("Scripting.Dictionary")
  Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
  Pos = InstrB(Pos,RequestBin,getByteString("name="))
  PosBeg = Pos+6
  PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
  Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
  PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
  PosBound = InstrB(PosEnd,RequestBin,boundary)
    If  PosFile<>0 AND (PosFile<PosBound) Then
    PosBeg = PosFile + 10
    PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))
    FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    UploadControl.Add "FileName", FileName
    Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
    PosBeg = Pos+14
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    UploadControl.Add "ContentType",ContentType
    PosBeg = PosEnd+4
    PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
    Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
    Else
    Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
    PosBeg = Pos+4
    PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
    Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    End If
    UploadControl.Add "Value" , Value 
    UploadRequest.Add name, UploadControl 
    BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
  Loop
End Sub
Function getByteString(StringStr)
  For i = 1 to Len(StringStr)
  char = Mid(StringStr,i,1)
  getByteString = getByteString & chrB(AscB(char))
  Next
End Function
Function getString(StringBin)
  getString =""
  For intCount = 1 to LenB(StringBin)
  getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
  Next
End Function

set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("data.mdb")
strsql = "SELECT * FROM [bruger]"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn, 1, 2
rs.AddNew
rs("blob") = filename
rs.Update
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Response.Clear
Response.redirect("test.asp")
End if
%>

<html>
<head>
  <title></title>

  <script language="JavaScript">
  function SetCookie (name, value) {var argv = SetCookie.arguments;var argc = SetCookie.arguments.length;var expires = (argc > 2) ? argv[2] : null;var path = (argc > 3) ? argv[3] : null;var domain = (argc > 4) ? argv[4] : null;var secure = (argc > 5) ? argv[5] : false;document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "")}
  function set_name(form) {var expdate = new Date ();expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
  var tekst = form3.y_tekst.value;SetCookie ("tekst", tekst, expdate)
  }
</script>
<link href="../../css/style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
  <br><form METHOD='Post' ENCTYPE='multipart/form-data' ACTION='godkendt.asp?key=1' id='form3' name='form3' onSubmit="return set_name(this.form);">
  <input TYPE="file" NAME="blob" class="input">
  <input TYPE="submit" value="Upload Billede" NAME="Enter" class="input">
  </form>
  </BODY>
</HTML>
Herefter tekst formular siden:
<%@ language="vbscript" codepage="1252" %>
<%
if cstr(Request.QueryString("mode")) = "new" then
    Session.Contents("userid") = 0
else
    if IsEmpty(Session.Contents("userid")) OR cstr(Session.Contents("userid") & "") = "" then
        Server.Transfer "login.asp"
    end if
end if

Server.Execute "setupConn.asp"

strConn = Session.Contents("ConnectionString")
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConn

if cstr(Request.Form("Opdater")) <> "" then
    SQLBeskrivelse = Replace(Request.Form("Beskrivelse"),"'","''")
    if len(SQLBeskrivelse) > 255 then
        SQLBeskrivelse = left(SQLBeskrivelse, 255)
    end if
   
    if Session.Contents("userid") > 0 then
        strSQL = "UPDATE bruger SET"
        strSQL = strSQL & " Navn='" & Replace(Request.Form("Navn"),"'","''") & "'"
        strSQL = strSQL & ", [Password]='" & Replace(Request.Form("Password"),"'","''") & "'"
        strSQL = strSQL & ", Email='" & Replace(Request.Form("Email"),"'","''") & "'"
        strSQL = strSQL & ", Adresse='" & Replace(Request.Form("Adresse"),"'","''") & "'"
        strSQL = strSQL & ", Bynavn='" & Replace(Request.Form("Bynavn"),"'","''") & "'"
        strSQL = strSQL & ", Kategori='" & Request.Form("Kategori") & "'"
        strSQL = strSQL & ", Beskrivelse='" & SQLBeskrivelse & "'"
        strSQL = strSQL & " WHERE ID=" & Session.Contents("userid")

        objConn.Execute strSQL
    else
        strSQL = "INSERT INTO bruger"
        strSQL = strSQL & "(Navn,[Password],Email,Adresse,Bynavn,Kategori,Beskrivelse,OprettetDato) "
        strSQL = strSQL & "VALUES("
        strSQL = strSQL & "'" & Replace(Request.Form("Navn"),"'","''") & "'"
        strSQL = strSQL & ",'" & Replace(Request.Form("Password"),"'","''") & "'"
        strSQL = strSQL & ",'" & Replace(Request.Form("Email"),"'","''") & "'"
        strSQL = strSQL & ",'" & Replace(Request.Form("Adresse"),"'","''") & "'"
        strSQL = strSQL & ",'" & Replace(Request.Form("Bynavn"),"'","''") &"'"     
        strSQL = strSQL & ",'" & Request.Form("Kategori") & "'"
        strSQL = strSQL & ",'" & SQLBeskrivelse & "'"
        strSQL = strSQL & ",#" & now & "#"
        strSQL = strSQL & ")"

        objConn.Execute strSQL
       
        set objRs = objConn.Execute("SELECT @@IDENTITY AS newId")
        if not objRs.EOF then
            Session.Contents("userid") = cstr(objRs("newId"))
        end if
        objRs.Close
        set objRs = nothing
    end if
   
    objConn.Close
    set objConn = nothing
    Response.Redirect "forside.asp"
end if

if cstr(Request.Form("Slet")) <> "" then
    strSQL = "DELETE FROM bruger WHERE ID=" & Session.Contents("userid")
    objConn.Execute strSQL

    objConn.Close
    set objConn = nothing
    Session.Contents("userid") = Empty
    Response.Redirect "forside.asp"
end if

if cstr(Request.Form("Logaf")) <> "" then
    objConn.Close
    set objConn = nothing
    Session.Contents("userid") = Empty
    Session.Abandon
    Response.Redirect "forside.asp"
end if

if Session.Contents("userid") > 0 then
    SaveButton = "Update"
    strSQL = "SELECT * FROM bruger WHERE ID = " & Session.Contents("userid")

    set objRs = objConn.Execute(strSQL)

  if not objRs.EOF then
        Navn = cstr(objRs("Navn") & "")
        Password = cstr(objRs("Password") & "")
        Email = cstr(objRs("Email") & "")
        Adresse = cstr(objRs("Adresse") & "")
        Bynavn = cstr(objRs("Bynavn") & "")
        Kategori = cstr(objRs("Kategori") & "")
        Beskrivelse = cstr(objRs("Beskrivelse") & "")
    end if

    objRs.close
    objConn.Close
    set objRs = nothing
    set objConn = nothing
else
    SaveButton = "Submit"
end if


strKategorier = "[Vælg kategori],,Kategori 1,Kategori 1,Kategori 2,kategori 3,kategori 3,kategori 4,kategori4 "
arrKategorier = Split(strKategorier, ",")

Kategorier = vbCrLf
for idx = 0 to ((ubound(arrKategorier) + 1) / 2) - 1
    strKategoriText = arrKategorier(idx * 2)
    strKategoriValue = arrKategorier(idx * 2 + 1)
    Kategorier = Kategorier & "<option value=""" & strKategoriValue & """"
    if strKategoriValue = Kategori then
        Kategorier = Kategorier & " SELECTED"
    end if
    Kategorier = Kategorier & ">" & strKategoriText & vbCrLf
next

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <style type="text/css">
<!--
.style5 {
    font-size: 24px;
    font-weight: bold;
}
-->
  </style>
<head>
    <title>Vedligehold brugeroplysninger</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
        .label { float:left; width:120px; }
    body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #06275B;
}
a {
    font-size: 12px;
    color: #06275B;
}
a:link {
    text-decoration: underline;
}
a:visited {
    text-decoration: underline;
    color: #06275B;
}
a:hover {
    text-decoration: none;
    color: #99CCFF;
}
a:active {
    text-decoration: underline;
    color: #06275B;
}
.style2 {font-family: Arial, Helvetica, sans-serif}
    .style4 {float: left; width: 120px; font-weight: bold; }
    </style>
</head>
  <body>


  <form action="<%=Request.ServerVariables("SCRIPT_NAME")%>" method="post">
  <table width="50%"  border="0">
    <tr>
      <td align="left" valign="top" nowrap><div align="left"><span class="style2"><span class="style3"><span class="style5"><font face="Arial Black, Impact, MS Sans Serif">GTO
          Recycle</font></span><img src="../mimages/cycle10.gif" width="70" height="77"></span></span></div></td>
    </tr>
  </table>
  <table width="57%" border="1" bordercolor="#99CCFF">
    <tr>
      <td width="11%" valign="top" bordercolor="#FFFFFF"><span class="style4">Name:</span></td>
      <td width="89%" bordercolor="#FFFFFF"><input type="text" maxlength="255" name="Navn" value="<%=Navn%>"></td>
    </tr>
    <tr>
      <td valign="top" bordercolor="#FFFFFF"><span class="style4">Password:</span></td>
      <td bordercolor="#FFFFFF"><input type="password" maxlength=50" name="Password" value="<%=Password%>"></td>
    </tr>
    <tr>
      <td valign="top" bordercolor="#FFFFFF"><span class="style4">Email:</span></td>
      <td bordercolor="#FFFFFF"><input type="text" maxlength=255" name="Email" value="<%=Email%>"></td>
    </tr>
    <tr>
      <td valign="top" bordercolor="#FFFFFF"><span class="style4">Adresse:</span></td>
      <td bordercolor="#FFFFFF"><input type="text" maxlength="255" name="Adresse" value="<%=Adresse%>"></td>
    </tr>
    <tr>
      <td valign="top" bordercolor="#FFFFFF"><span class="style4">Bynavn:</span></td>
      <td bordercolor="#FFFFFF"><input type="text" maxlength="50" name="Bynavn" value="<%=Bynavn%>"></td>
    </tr>
    <tr>
      <td valign="top" bordercolor="#FFFFFF"><span class="style4">Kategori:</span></td>
      <td bordercolor="#FFFFFF"><select name="Kategori" class="style2">
          <%=Kategorier%> </select></td>
    </tr>
    <tr>
      <td valign="top" bordercolor="#FFFFFF"><span class="style4">Beskrivelse:</span></td>
      <td bordercolor="#FFFFFF"><textarea name="Beskrivelse" cols="50" rows="5"><%=Beskrivelse%></textarea></td>
    </tr>
    <tr>
      <td bordercolor="#FFFFFF">&nbsp;</td>
      <td bordercolor="#FFFFFF"><input name="Opdater" type="submit" class="style4" value="<%=SaveButton%>">
        <input name="Slet" type="submit" class="style4" value="Delete"> <input name="Logaf" type="submit" class="style4" value="Logoff"></td>
    </tr>
  </table>
  <p><br>
    <span class="label">&nbsp;</span> <br>
    <br>
  </p>
  </form>

  </body>
</html>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester