Avatar billede vtm Nybegynder
17. juni 2003 - 00:20 Der er 10 kommentarer

Upload filer og ændre navn efter bruger

Jeg har et lille problem og ved ikke helt hvordan jeg skal gribe det an, så derfor er jeg her. Det skal siges er ny i ASP programmerings området så er det sagt.

Jeg har en uploader, som virker fint, det eneste problem er at jeg gerne vil ha den ind i mit bruger system også at den ændre filnavnet, så det eksempelvis bliver pivskid.jpg til bruger1.jpg

Ved ikke hvad i har brug for af kode, men skriv så skal jeg nok lægge det ind.
Avatar billede vtm Nybegynder
17. juni 2003 - 00:21 #1
Uploaden består af 3 filer
Outputfile
upload
uploadfile
Avatar billede vtm Nybegynder
17. juni 2003 - 00:23 #2
OUTPUTFILE

<%
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
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")
'pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14
'Response.Write (Request.ServerVariables("PATH_INFO"))
Set MyFile = ScriptObject.CreateTextFile(Server.mappath(""&filename))
For i = 1 to LenB(value)
    MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close    %>
<!--#include file="upload.asp"-->
Avatar billede vtm Nybegynder
17. juni 2003 - 00:24 #3
UPLOAD




<%
Sub BuildUploadRequest(RequestBin)
    'Get the boundary
    PosBeg = 1
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
    boundaryPos = InstrB(1,RequestBin,boundary)
    'Get all data inside the boundaries
    Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
        'Members variable of objects are put in a dictionary object
        Dim UploadControl
        Set UploadControl = CreateObject("Scripting.Dictionary")
        'Get an object name
        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)
        'Test if object is of file type
        If  PosFile<>0 AND (PosFile<PosBound) Then
            'Get Filename, content-type and content of file
            PosBeg = PosFile + 10
            PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))
            FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
            'Add filename to dictionary object
            UploadControl.Add "FileName", FileName
            Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
            PosBeg = Pos+14
            PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
            'Add content-type to dictionary object
            ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
            UploadControl.Add "ContentType",ContentType
            'Get content of object
            PosBeg = PosEnd+4
            PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
            Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
            Else
            'Get content of object
            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
        'Add content to dictionary object
    UploadControl.Add "Value" , Value   
        'Add dictionary object to main dictionary
    UploadRequest.Add name, UploadControl   
        'Loop to next object
        BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
    Loop

End Sub

'String to byte string conversion
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
    char = Mid(StringStr,i,1)
    getByteString = getByteString & chrB(AscB(char))
Next
End Function

'Byte string to string conversion
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
    getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>
Avatar billede vtm Nybegynder
17. juni 2003 - 00:25 #4
UPLOADFILE

<form METHOD="Post" ENCTYPE="multipart/form-data" ACTION="outputFile.asp" id="form3" name="form3">
<input TYPE="file" NAME="blob" size="20"><br>
<input TYPE="submit" value="Upload billede" NAME="Enter">
Avatar billede vtm Nybegynder
17. juni 2003 - 00:29 #5
I bruger systemet er der 5 filer til oprettelse, login og beskyttede sider.
bruger.asp = beskyttede side
db = database filen
opret.asp = filen hvor man opretter sig
opret_data.asp = opretter dataer i dben
Avatar billede vtm Nybegynder
17. juni 2003 - 00:30 #6
OPRET_DATA

<%

Const adOpenKeyset = 1
Const adLockOptimistic = 3

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db.mdb") & ";UID=admin;PWD=;"

    Set rs = Server.CreateObject("ADODB.RecordSet")
    strSQL = "Select * From users"
    rs.Open strSQL, Conn, adOpenKeyset, adLockOptimistic

      rs.AddNew
      rs("Username") = Request.form("bnavn")
      rs("Password") = Request.form("pas")
      rs("RigtigNavn") = Request.form("rnavn")
      rs("Email") = Request.form("email")
      rs.Update

    rs.Close
    Set rs = Nothing

Conn.Close
set Conn = Nothing
%></p>
<html>

<head>
<META HTTP-EQUIV="Refresh" CONTENT="5;URL=default.asp">

</style>
</head>

<BODY text="#000000" topmargin="10" leftmargin="0"
rightmargin="0">
<center><FONT FACE="Arial" SIZE="+2">Du kan nu benytte admin Funktionen.</FONT></center>
</body>
</html>
Avatar billede vtm Nybegynder
17. juni 2003 - 00:30 #7
OPRET

<html>
<form action="oprat_data.asp" method="POST" class="css">

<head>
</head>
<body text="#000000">
<body" topmargin="10" leftmargin="0" rightmargin="0">
<p><b><font size="4" face="Arial">Opret Brugernavn og Password.</font></b></p>
    <div align="center"><center><table border="0" cellpadding="2"
    cellspacing="0" width="90%">
        <tr>
            <td align="left" width="40%" valign="top"><font size="3" face="Arial">Brugernavn:</font></td>
            <td colspan="2" width="60%"><INPUT TYPE="text" NAME="bnavn" size="20"></td>
        </tr>
        <tr>
            <td align="left" width="40%" valign="top"><font size="3" face="Arial">Password</font></td>
            <td colspan="2" width="60%"><INPUT TYPE="text" NAME="pas" size="20"></td>
        </tr>
        <tr>
            <td align="left" width="20%" valign="top"><font size="3" face="Arial">Rigtig
              Navn:</font></td>
            <td colspan="2" width="80%"><INPUT TYPE="text" NAME="rnavn" size="20"></td>
        </tr>
        <tr>
            <td align="Left" valign="top" width="20%"><font size="3" face="Arial">E-mail:</font></td>
            <td valign="top" width="80%">
            <INPUT TYPE="text" NAME="email" size="20" value="@">
            </td>
        </tr>
        <tr>
            <td width="20%"></td>
            <td colspan="2" width="80%"><input type="submit" name="B1" value="Tilf&oslash;j"> <INPUT TYPE="reset" NAME="Slet"></td>
        </tr>
    </table>
    </center></div>
</form>

<p align="center"><a href="default.asp"><font face="Arial">Forside</font></a></p>

</body>

</html>
Avatar billede vtm Nybegynder
17. juni 2003 - 00:31 #8
DEFAULT (glemte jeg længere oppe, men det er den man logger ind fra)

<%
SET rs = Server.CreateObject("ADODB.Connection")
rs.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("DB.mdb")

If Request("mode") = "Check" then

Sql = "Select Count(*) as Found from users where (username = '" & Request("username") & "') and (password ='" & Request("password") & "')"
Set Login = Rs.Execute(Sql)
if Login("Found") = 0 then
Session("login") = 0
error = "Du har skrevet en forkert Brugernavn eller Password prøv igen eller kontakt Webmarsteren."
else
Session("Login") = 1
Session("password-session") = Request("username")
Response.Redirect "bruger.asp"
end if
else
end if

%>
<HTML>
<HEAD>
<title></title>
</HEAD>
<BODY text="#000000">
<form method="POST" action="Default.asp">
<input type="hidden" name="mode" VALUE="Check">
<center>
<table border="0" width="50%" cellspacing="1">
  <tr>
    <td width="100%"><%=error%></td>
  </tr>
</table>
<p><b><font face="Arial" size="4">Skriv Brugernavn og Password for at logge ind..</font></b></p>
  <div align="center">
    <center>
    <table border="0" width="20%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="50%"><font face="Tahoma">Username:</font></td>
        <td width="50%"><font face="Tahoma" size="2"><input type="text" name="username" size="20" style="font-size: 8 pt"></font></td>
      </tr>
      <tr>
        <td width="50%"><font face="Tahoma">Password:</font></td>
        <td width="50%"><font face="Tahoma" size="2"><input type="password" name="password" size="20" style="font-size: 8 pt"></font></td>
      </tr>
      <tr>
        <td width="50%"><font face="Tahoma" size="2"><input type="submit" value="Login" name="submit" style="font-size: 8 pt"></font></td>
        <td width="50%">&nbsp;</td>
      </tr>
    </table>
    </center>
  </div>
</form>

</center>
<p align="center"><a href="oprat.asp"><font face="Arial">Oprat ny</font></a></p>

</BODY>
</HTML>
Avatar billede vtm Nybegynder
17. juni 2003 - 00:32 #9
BRUGER

<%
Response.Buffer = True
SET rs = Server.CreateObject("ADODB.Connection")
rs.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db.mdb")

if request("Mode") = "logaf" then
session.Abandon
Response.Redirect("default.asp")
end if

IF Session("password-session") = "" Then
Response.Redirect("Default.asp")
end if


Sql = "Select * FROM users WHERE username = '" & session("password-session") & "'"
set rs = rs.Execute(SQL)
%>

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

<body text="#000000">

<table border="0" width="100%" cellspacing="1">
  <tr>
    <td width="42%"><font face="Arial">Velkommen <% = rs("RigtigNavn") %> </font> </td>
    <td width="48%"></td>
    <td width="10%">
<a href="bruger.asp?mode=logaf"><font face="Arial">Log af</font></a>
    </td>
  </tr>
</table>
<table border="0" width="100%" cellspacing="0" height="151" cellpadding="0">
  <tr>
    <td width="100%" height="147" valign="top"><font face="Arial">Du er nu
      logget ind.</font></td>
  </tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="13%"></td>
    <td width="61%"></td>
    <td width="26%"></td>
  </tr>
</table>
Avatar billede vtm Nybegynder
17. juni 2003 - 16:45 #10
Virkelig en god hjælp
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
Kurser inden for grundlæggende programmering

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