Hjælp til multiupload
Er der nogen, der kan gøre således, at jeg kan uploade 50 filer af gangen via dette script, og højst 1 MB til hver fil?<% Response.Buffer = True %>
<%
strPageName = "index.asp"
strUploadFolder = "upls"
strAllow = ".jpg,.jpeg,.JPG,.JPEG,.gif,.GIF,.png,.PNG"
strFileShow = 1
strFixAllow = strAllow
strFixAllow = Replace(strFixAllow,","," ")
Files_upload = Server.MapPath(strUploadFolder)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.getFolder(Files_upload)
If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
Set Upload = get_upload_files()
fcontent = Upload("upload").Item("content")
filnavn = lcase(extract_filename(Upload("upload").Item("filename")))
if filnavn <> "" then
else
session("fejl") = "1"
response.redirect("index.asp")
end if
extension = right(filnavn,4)
filnavn = Replace(filnavn,"æ","ae")
filnavn = Replace(filnavn,"ø","oe")
filnavn = Replace(filnavn,"å","aa")
fundet=false
for i=len(filnavn) to 1 step -1 'læs baglæns
if mid(filnavn,i,1)="." then 'er tegnet et punktum?
if fundet=true then 'har der været et punktum allerede
mid(filnavn,i,1)="_" 'hvis ja, så erstat dette med _
else 'ellers
fundet=true 'er det første (=det sidste, vi læser baglæns) punktum fundet
end if
end if
next
If objFSO.FileExists(Files_upload & "\" & filnavn) Then
Session("mess") = "Der findes allerede en fil med det navn. Omdøb venligst filen!"
Response.Redirect strPageName
Else
If instr(strAllow,extension) then
Set File = objFSO.CreateTextFile(Files_upload & "\" & filnavn)
Else
Session("mess") = "Filen er ikke godkendt. Filerne skal ende på <b>" & strAllow & "</b> for at blive godkendt."
Response.Redirect strPageName
End If
End If
For i = 1 to LenB(fcontent)
File.Write chr(AscB(MidB(fcontent, i, 1)))
Next
File.Close: Set File = Nothing
Session("mess") = "Billedet er nu uploadet!"
Session("image") = filnavn
Response.Redirect "index.asp"
End If %>
<form name="frmUpload" method="post" enctype="multipart/form-data" action="<%=strPageName%>">
<input type="file" name="upload" style="width: 100%; margin-top: 2px; margin-bottom: 2px;" size="40"><br />
<input type="submit" value="Upload" name="sbmt" style="width: 100%; margin-top: 2px; margin-bottom: 2px;" onClick="Post();"><br />
</form>
Her har du mulighed for, at uploade op til 1 MB af gangen. Følgende filendelser er tilladte:<br />
.<b>JPG</b>, .<b>JPEG</b>, .<b>GIF</b> og .<b>PNG</b><br />
Der vil senere blive tilføjet flere til listen.
<font color="#FF0000"><% If Session("mess") <> "" Then : Response.Write "<br /><br /><b>" & Session("mess") & "</b><br /><br />" : Session.Contents.Remove("mess") %></font>
<% if session("image") <> "" then %><input type="text" name="filnavn" style="width: 100%; margin-top: 2px; margin-bottom: 2px;" value="[img] http://www.glasoksen.dk/upls/<%=session("image")%>[/img]"><br />
<a href=" http://www.glasoksen.dk/upls/<%=session("image")%>">http://www.glasoksen.dk/upls/<%=session("image")%></a><br /><br /><% session("image") = "" %><% end if %>
<%
Function get_upload_files()
Set upload_object = Server.CreateObject("Scripting.Dictionary")
request_binaries = Request.BinaryRead(Request.TotalBytes)
position_start = 1
position_end = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
boundary = MidB(request_binaries, position_start, (position_end - position_start))
boundary_pos = InstrB(1, request_binaries, boundary)
Do Until (boundary_pos = InstrB(request_binaries, boundary & get_byte_string("--")))
If Not(Response.IsClientConnected) Then Response.End
position_start = (InstrB(InstrB(boundary_pos, request_binaries, get_byte_string("Content-Disposition")), request_binaries, get_byte_string("name=")) + 6)
position_end = InstrB(position_start, request_binaries, get_byte_string(chr(34)))
name = get_string(MidB(request_binaries, position_start, (position_end - position_start)))
pos_file = InstrB(boundary_pos, request_binaries, get_byte_string("filename="))
If ((pos_file <> 0) AND (pos_file < InstrB(position_end, request_binaries, boundary))) Then
upload_object.Add name, Server.CreateObject("Scripting.Dictionary")
position_start = (pos_file + 10)
position_end = InstrB(position_start, request_binaries, get_byte_string(chr(34)))
upload_object.item(name).Add "filename", get_string(MidB(request_binaries, position_start, (position_end - position_start)))
position_start = (InstrB(position_end, request_binaries, get_byte_string("Content-Type:")) + 14)
position_end = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
upload_object.item(name).Add "content-type", get_string(MidB(request_binaries, position_start, (position_end - position_start)))
position_start = (position_end + 4)
position_end = InstrB(position_start, request_binaries, boundary) - 2
upload_object.item(name).Add "size", ((position_end - position_start))
upload_object.item(name).Add "content", MidB(request_binaries, position_start, (position_end - position_start))
End If
boundary_pos = InstrB(boundary_pos + LenB(boundary), request_binaries, boundary)
Loop
Set get_upload_files = upload_object
End Function
Function get_byte_string(str)
For cnt = 1 to Len(str)
get_byte_string = get_byte_string & chrB(AscB(Mid(str, cnt, 1)))
Next
End Function
Function get_string(str)
For cnt = 1 to LenB(str)
get_string = get_string & chr(AscB(MidB(str, cnt, 1)))
Next
End Function
Function extract_filename(filename)
extract_filename = Right(filename, Len(filename) - InStrRev(filename, "\", -1, 1))
End Function
%>
Med venlig hilsen
Martin Haugaard