-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_file.asp
98 lines (96 loc) · 3.58 KB
/
upload_file.asp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!--#include file="vbscript.asp"-->
<% SERVER.SCRIPTTIMEOUT = 4800 %>
<%
ON ERROR RESUME NEXT
'Stores only files with size less than MaxFileSize
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %>
<!--#INCLUDE FILE="upload.motobit.asp"-->
<%
Server.ScriptTimeout = 2000
Form.SizeLimit = &HF000000
'{b}Set the upload ID for this form.
'Progress bar window will receive the same ID.
if len(Request.QueryString("UploadID"))>0 then
Form.UploadID = Request.QueryString("UploadID")'{/b}
else
Randomize
Form.UploadID = clng(rnd * &H7FFFFFFF)
end if
'was the Form successfully received?
Const fsCompleted = 0
If Form.State = fsCompleted Then 'Completed
'was the Form successfully received?
If Form.State = 0 then %><%
Dim parent_folder
Dim fileName, saveAs, extension
Dim relativeTargetPath, absolute_path
Dim fso: Set fso = Server.CreateObject("Scripting.FileSystemObject")
parent_folder=Request.QueryString("parentFolder")'TRIM(Form("parentFolder").Value)
IF parent_folder="" THEN
parent_folder="FilesRepository"
END IF
%>
{
files: [{}
<% DIM File
Response.ContentType = "application/json"
FOR EACH File IN Form.Files.Items
saveAs=Request.QueryString("saveAs")'TRIM(Form("saveAs").Value)
extension = fso.GetExtensionName(Form.Files.Item(File.Name).FileName)
Form.Files.Item(File.Name).FileName = "tmp_"&Form.UploadID&"."&extension
IF TRIM(saveAs)<>"" THEN
Form.Files.Item(File.Name).FileName = fso.GetBaseName(saveAs)&"."&extension
END IF
'fileName = Form.Files.Items.Item(0).FileName
relativeTargetPath=parent_folder & "/" & Form.Files.Item(File.Name).FileName
' Ruta donde se va a guardar el file
parent_folder = server.MapPath("\")&"\"&parent_folder
If Not fso.FolderExists(parent_folder) Then
CreateFolder parent_folder
'fso.CreateFolder (parent_folder)
End If
'absolute_path = parent_folder & "\" & Form.Files.Item(File.Name).FileName
'response.write "absolute_path: "&absolute_path: response.end
'response.end
%>
<% Form.Files.Save parent_folder %>
<% IF Err.Number<>0 THEN %>
,{
success: false,
statusMessage: "Error: <%= REPLACE(Err.Description, "[Microsoft][ODBC SQL Server Driver][SQL Server]", "") %><% IF session("user_id")=1 THEN response.write " \n\n"&sSQL %>"
}
<% ELSE
response.AddHeader "File-Name", relativeTargetPath
%>
,{
uploadId: "<%= Form.UploadID %>",
sourceId: "<%= File.Name %>",
file: "<%= relativeTargetPath %>",
fileExtension: "<%= extension %>",
originalFile: "<%= REPLACE(File.FilePath, "\", "\\") %>",
fileName:"<%= File.FileName %>",
parentFolder:"<%= parent_folder %>",
status:"success"
}
<% END IF
NEXT %>
],
statusMessage:"<%= Form.Files.Count %> file(s) uploaded to <%= Request.ServerVariables("HTTP_HOST") %> (<%= relativeTargetPath %>)"
}
<%
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD %>
<script language="JavaScript">
var resultObject = new Object();
resultObject.status = "error";
resultObject.statusMessage = "<% Select case Form.State
case fsSizeLimit: %> Source form size(<%= Form.TotalBytes %> B) exceeds form limit(<%= Form.SizeLimit %> B) <% case else %> Some form error.<% end Select %> ";
alert(resultObject.statusMessage)
window.close();
</script>
<% response.end
End If'Form.State = 0 then %>
<% END IF %>