📄 admin_upload.asp
字号:
<%
if Session("Admin") = False or IsNull (Session("Admin")) = True then
Response.Redirect("Admin_login.asp")
end if
%>
<%
Dim qStrDir
Dim targetis
qStrDir=Request.QueryString("dir")
targetis=Request.QueryString("targetis")
%>
<html>
<head>
<title>Upload file</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
<!--
function insertStr(strValue,anh){
window.opener.document.frmAddProduct[anh].value=strValue;
}
function getFileExtension(filePath) { //v1.0
fileName = ((filePath.indexOf('/') > -1) ? filePath.substring(filePath.lastIndexOf('/')+1,filePath.length) : filePath.substring(filePath.lastIndexOf('\\')+1,filePath.length));
return fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);
}
function checkFileUpload(form,extensions) { //v1.0
document.MM_returnValue = true;
if (extensions && extensions != '') {
for (var i = 0; i<form.elements.length; i++) {
field = form.elements[i];
if (field.type.toUpperCase() != 'FILE') continue;
if (field.value == '') {
alert('File is required!');
document.MM_returnValue = false;field.focus();break;
}
if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {
alert('This file is not allowed for uploading!');
document.MM_returnValue = false;field.focus();break;
} } }
}
//-->
</script>
</HEAD>
<Body>
<%
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
if PosEnd = 0 then
Response.Write "<b>Form was submitted with no ENCTYPE=""multipart/form-data""</b><br>"
Response.Write "Please correct the form attributes and try again."
Response.End
end if
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))
FileName = Mid(FileName,InStrRev(FileName,"\")+1)
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 = FileName
ValueBeg = PosBeg-1
ValueLen = 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))
ValueBeg = 0
ValueEnd = 0
End If
UploadControl.Add "Value" , Value
UploadControl.Add "ValueBeg" , ValueBeg
UploadControl.Add "ValueLen" , ValueLen
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
Function UploadFormRequest(name)
on error resume next
if UploadRequest.Item(name) then
UploadFormRequest = UploadRequest.Item(name).Item("Value")
end if
End Function
UploadQueryString = Replace(Request.QueryString,"AF_upload=true","")
if mid(UploadQueryString,1,1) = "&" then
UploadQueryString = Mid(UploadQueryString,2)
end if
AF_uploadAction = CStr(Request.ServerVariables("URL")) & "?AF_upload=true"
If (Request.QueryString <> "") Then
if UploadQueryString <> "" then
AF_uploadAction = AF_uploadAction & "&" & UploadQueryString
end if
End If
If (CStr(Request.QueryString("AF_upload")) <> "") Then
AF_redirectPage = "success.asp"
If (AF_redirectPage = "") Then
AF_redirectPage = CStr(Request.ServerVariables("URL"))
end if
RequestBin = Request.BinaryRead(Request.TotalBytes)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
AF_keys = UploadRequest.Keys
for AF_i = 0 to UploadRequest.Count - 1
AF_curKey = AF_keys(AF_i)
if UploadRequest.Item(AF_curKey).Item("FileName") <> "" then
AF_value = UploadRequest.Item(AF_curKey).Item("Value")
AF_valueBeg = UploadRequest.Item(AF_curKey).Item("ValueBeg")
AF_valueLen = UploadRequest.Item(AF_curKey).Item("ValueLen")
if AF_valueLen = 0 then
Response.Write "<p><B>Đă có một lỗi xảy ra trong quá tŕnh bạn upload file!</B><br><br>"
Response.Write "Tên File: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "<br>"
Response.Write "File không tồn tại hoặc rỗng.<br>"
Response.Write "Bạn vui ḷng kiểm tra và <A HREF=""javascript:history.back(1)"">thử lại</a>"
response.End
end if
Dim AF_strm1, AF_strm2
Set AF_strm1 = Server.CreateObject("ADODB.Stream")
Set AF_strm2 = Server.CreateObject("ADODB.Stream")
AF_strm1.Open
AF_strm1.Type = 1 'Binary
AF_strm2.Open
AF_strm2.Type = 1 'Binary
AF_strm1.Write RequestBin
AF_strm1.Position = AF_ValueBeg
AF_strm1.CopyTo AF_strm2,AF_ValueLen
AF_curPath = "../images/"&qStrDir&"/"
fname=UploadRequest.Item(AF_curKey).Item("FileName")
on error resume next
AF_strm2.SaveToFile Trim(Server.mappath(AF_curPath))& "\" & UploadRequest.Item(AF_curKey).Item("FileName"),2
if err then
Response.Write "<p><B>Đă có một lỗi xảy ra trong quá tŕnh bạn upload file!</B><br><br>"
Response.Write "Tên File: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "<br>"
Response.Write "Thư mục để upload file vào không tồn tại hoặc không được phép upload file vào đó.<br>"
Response.Write "Bạn vui ḷng kiểm tra và <A HREF=""javascript:history.back(1)"">thử lại</a>"
err.clear
response.End
end if
end if
next
If (AF_redirectPage <> "") Then
%>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse: collapse" bgcolor="#ECE9D8" bordercolorlight="#F4F2E8">
<tr>
<td>
<table border="0" width="100%" cellspacing="1">
<tr>
<td bgcolor="#00557D"><b>
<font face="Tahoma" size="2" color="#FFFFFF"> Upload Picture</font></b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="0" width="100%" height="112">
<tr>
<td height="71">
<p align="center" style="margin-top: 2px; margin-bottom: 2px">
<b><font face="Tahoma">Upload thành công!</font></b></p>
<p align="center" style="margin-top: 2px; margin-bottom: 2px">
<font face="Tahoma" size="2">Bấm vào đây
<a href="Javascript:insertStr('images/<%=qStrDir%>/<%=fname%>','<%=targetis%>');">
(images/<%=qStrDir%>/<%=fname%>)</a></font></p>
<p align="center" style="margin-top: 2px; margin-bottom: 2px">
<font face="Tahoma" size="2">để đưa đường dẫn vào hộp nhập.</font></td>
</tr>
<tr>
<td>
<p align="center">
<input onclick="javascript:history.back();" type="button" value="Continue" name="Continue">
<input onclick="Javascript:insertStr('images/<%=qStrDir%>/<%=fname%>','<%=targetis%>');javascript:window.close();" type="button" value="Close" name="Close1"></td>
</tr>
</table>
</td>
</tr>
</table>
<%
end if
Else
if UploadQueryString <> "" then
UploadQueryString = UploadQueryString & "&AF_upload=true"
else
UploadQueryString = "AF_upload=true"
end if
%>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse: collapse" bgcolor="#ECE9D8" bordercolorlight="#F4F2E8">
<tr>
<td>
<table border="0" width="100%" cellspacing="1">
<tr>
<td bgcolor="#00557D"><b>
<font face="Tahoma" size="2" color="#FFFFFF"> Upload Picture</font></b></td>
</tr>
<tr>
<form name="ASP" method="POST" enctype="multipart/form-data" action="admin_upload.asp?dir=<%=qStrDir%>&targetis=<%=targetis%>&AF_upload=true">
<td>
<table border="0" width="100%">
<tr>
<td width="40%" height="10">
</td>
<td width="60%" height="10">
</td>
</tr>
<tr>
<td width="40%">
<p align="right"><font face="Tahoma" size="2">File name:
</font></td>
<td width="60%">
<input type="file" name="Files" size="25">
</td>
</tr>
<tr>
<td width="40%" height="5"></td>
<td width="60%" height="5">
</td>
</tr>
<tr>
<td width="40%"> </td>
<td width="60%">
<input type="submit" value="Upload" name="Submit1">
<input onclick="javascript:window.close();" type="button" value="Close" name="Close">
</td>
</tr>
<tr>
<td width="40%" height="5"></td>
<td width="60%" height="5"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</td>
</tr>
</table>
<%End if%>
</Body>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -