Jag använder denna koden, filen heter upload_killar.asp Stäng av "vänliga meddelanden" i din webbläsare så du får veta vad felet är och på vilken rad.Uppladdning av bild i Windows Advanced Server 2000 (IIS)
När ja laddar upp bild och klickar "Ladda upp" Får jag meddelandet "Sidan kan inte visas"
Kod:
--------------------------------------------------------------------------------
<%@EnableSessionState=True%>
<%Response.Buffer=True%>
<%Response.Expires=0
UPLOAD_PATH = Server.MapPath("killar")
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Set Folder = Fso.getFolder(UPLOAD_PATH)
If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
Set Upload = get_upload_files()
fcontent = Upload("upload").Item("content")
allowlist = ".gif,.jpg,.jpeg,.JPG,.GIF,.JPEG"
extension = right(extract_filename(Upload("upload").Item("filename")),4)
If Fso.FileExists(UPLOAD_PATH & "/" & extract_filename(Upload("upload").Item("filename"))) Then
Session("mess") = "En fil med det namnet finns redan!"
Response.Redirect "upload_killar.asp"
Else
If instr(allowlist,extension) then
Set File = Fso.CreateTextFile(UPLOAD_PATH & "/" & extract_filename(Upload("upload").Item("filename")))
Else
Session("mess") = "Du får <b>inte</b> skicka upp filen med det filformatet.<br>Endast <b>" & allowlist & "</b> är godkända."
Response.Redirect "upload_killar.asp"
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("fil") = extract_filename(Upload("upload").Item("filename"))
Session("visa") = "ok"
Response.Redirect "skicka_killar.asp"
End If %>
<html>
<head>
<title>¤ VACKRAST.COM ¤</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javaScript">
function tecken()
{
if (document.frmUpload.upload.value=="")
{
alert("Du måste ladda upp en bild, som har filändelsen JPG eller GIF");
return false;
}
}
</script>
</head>
<body bgcolor="#AF0D0D" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<table width="400" border="0">
<form name="frmUpload" method="post" enctype="multipart/form-data" action="upload_killar.asp" onSubmit="return tecken()">
<tr>
<td>
<input type="file" name="upload" size="35" style="font-size: 8pt; font-family: verdana, arial">
<input type="submit" value="Ladda upp" style="font-size: 8pt; font-family: verdana, arial">
</td>
</tr>
<%If Session("mess") <> "" Then%>
<tr>
<td class="normal"><%=Session("mess")%>
<%Session("mess") = ""%>
</td>
</tr>
<%End If%>
</form>
</table>
<%
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
%>Sv: Uppladdning av bild i Windows Advanced Server 2000 (IIS)
/Pelle