|
| |
|
|
J-man
Posts: 936 From: Canada Status: offline
|
publish js files on your server - 4/25/2003 17:36:33
Use to publish *.js scripts on your server, stripping off all the comments and extra spaces (make sure you do not miss any semicolons). Depending on your coding habbits the size can be reduced by a factor of two or so. Also you give some extra headache to those stealing your work :) . code:-------------------------------------------------------------------------------- <%@ Language =JScript EnableSessionState = False%> <% Response.Buffer = true; Response.Expires = 0; %> <!--#include file=" FileUpload.asp" --> <html> <head> <title>Publish JavaScript</title> </head> <body> <% scriptsFolder = ' ClientScripts/' ; if(Request.QueryString(' Submit' )==' True' ) { fileName = fileFields(0,2); pFN=/.*\\(.*)/; fileName = fileName.replace(pFN," $1" ); if(fileName.length > 0) { code = fileFields(0,1); %> <h3>Publishing file: <%Response.Write(fileName);%> </h3> <p>Orginal Code: (size: <%Response.Write(0.001*code.length);%> KB)</p> <% pStartComment = /\/\*/; pEndComment = /\*\//; pSLComment = /\/\/[^\n]*/g; pExtraSpace = /\s+/g; pSpace = /\s?([\{\};\=\(\)\\\/\+\*-])\s?/g; pieces = code.split(pStartComment); code = ' ' ; for(i=0; i<pieces.length;i++) { code += pieces.split(pEndComment)[1]; } code = code.replace(pSLComment,' ' ); code = code.replace(pExtraSpace,' ' ); code = code.replace(pSpace,' $1' ); savePath = Server.MapPath(scriptsFolder + fileName); var fso = Server.CreateObject(" Scripting.FileSystemObject" ); var scriptFile = fso.CreateTextFile(savePath, true); scriptFile.Write(code); scriptFile.Close(); %> <p>Published file: (size: <%Response.Write(0.001*code.length);%> KB)</p> <% } else { %> <h3>File not found</h3> <% } } else { %> <form action=" PublishJS.asp?Submit=True" method=" post" enctype=" multipart/form-data" > <input type=" file" name=" File" value=" " style=" width:100%;" /> <input type=" submit" name=" Submit" value=" Submit" /> </form> <% } %> </body> </html> include: <SCRIPT LANGUAGE=" VBScript" RUNAT=" server" > Server.ScriptTimeout = 5000 Function GetFieldName(sField) Dim iStart, iEnd iStart = InStr(sField, " name=" ) iEnd = InStr(iStart + 6, sField, Chr(34) & " ;" ) If iEnd = 0 Then iEnd = inStr(iStart + 6, sField, Chr(34)) End If GetFieldName = Mid(sField, iStart + 6, iEnd - (iStart + 6)) End Function Function GetFileName(sField) Dim iStart, iEnd iStart = InStr(sField, " filename=" ) iEnd = InStr(sField, Chr(34) & vbCrLf) GetFileName = Mid(sField, iStart + 10, iEnd - (iStart + 10)) End Function Function GetFileType(sField) Dim iStart iStart = InStr(sField, " Content-Type: " ) GetFileType = Mid(sField, iStart + 14) End Function Dim sContentType Dim aCTSplit Dim sFormData Dim bFormData Dim aBoundary Dim iBoundary Dim aFormData Dim textFields, fileFields(9,3) Dim iNFiles Dim iEndInfo Dim FieldInfo, FieldValue Dim i sContentType = Request.ServerVariables(" HTTP_CONTENT_TYPE" ) If InStr(sContentType," multipart/form-data" ) Then aCTSplit = Split(sContentType, " ;" ) sFormData = " " bFormData = Request.BinaryRead(Request.TotalBytes) For i = 1 to LenB(bFormData) sFormData = sFormData & Chr(AscB(MidB(bFormData,i,1))) Next aBoundary = Split(Trim(aCTSplit(1)), " =" ) iBoundary = Trim(aBoundary(1)) aFormData = Split(sFormData, iBoundary) Set textFields = CreateObject(" Scripting.Dictionary" ) iNFiles = 0 For i = 0 to UBound(aFormData) iEndInfo = InStr(aFormData(i), vbCrLf & vbCrLf) If iEndInfo > 0 Then FieldInfo = Mid(aFormData(i), 3, iEndInfo - 3) FieldValue = Mid(aFormData(i), iEndInfo + 4,Len(aFormData(i)) - iEndInfo - 7) If (InStr(FieldInfo, " filename=" ) > 0) Then fileFields(iNFiles, 0) = GetFieldName(FieldInfo) fileFields(iNFiles, 1) = FieldValue fileFields(iNFiles, 2) = GetFileName(FieldInfo) fileFields(iNFiles, 3) = GetFileType(FieldInfo) iNFiles = iNFiles + 1 Else textFields.add GetFieldName(FieldInfo), FieldValue End If End If Next End If </SCRIPT> //Vladdy//
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|