<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 手机拍照上传系统 - xiao源码网 xiaoyau.0ql.top <% ' ==================== 经典ASP无组件上传处理 ==================== ' 功能: 二维码展示 + 手机拍照上传(二进制解析) ' ======================================================== Response.Expires = 0 Response.CodePage = 65001 Response.Charset = "UTF-8" ' 定义上传文件夹 upload_folder="upload/" method = Request.ServerVariables("REQUEST_METHOD") ' 判断是否有文件上传 (POST 且 TotalBytes > 0) If method = "POST" And Request.TotalBytes > 0 Then Call ProcessPhotoUpload() Response.End() End If Dim mode mode = Request.QueryString("mode") If mode = "camera" Then ' 相机模式 %>
拍照上传
<% Else ' 二维码模式 %>
随身拍照助手
二维码加载中...
<% End If ' ==================== 获取网址函数 ==================== Function GetBaseUrl() Dim url, protocol If Request.ServerVariables("HTTPS") = "on" Then protocol = "https://" Else protocol = "http://" End If GetBaseUrl = protocol & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME") End Function ' ==================== 照片上传处理 ==================== Sub ProcessPhotoUpload() On Error Resume Next totalBytes = Request.TotalBytes binData = Request.BinaryRead(totalBytes) Set a = CreateObject("adodb.stream") a.Type = 1 a.Open a.Write binData a.Position = 0 b = a.Read c = ChrB(13) & ChrB(10) d = InStrB(b, c) e = InStrB(d + 1, b, c) Set f = CreateObject("adodb.stream") f.Type = 1 f.Open a.Position = d + 1 a.CopyTo f, e - d - 3 f.Position = 0 f.Type = 2 f.CharSet = "utf-8" g = f.ReadText f.Close ' 解析文件名 h = Mid(g, InStrRev(g, "\") + 1, e) h = Mid(h, InStrRev(h, "=") + 2) h = Trim(h) ' 解析文件数据位置 i = InStrB(b, c & c) + 4 j = InStrB(i + 1, b, LeftB(b, d - 1)) - i - 2 k = InStrB(i + j + 1, b, c & c) + 4 l = InStrB(k + 1, b, LeftB(b, d - 1)) - k - 2 m = InStrB(k + l + 1, b, c & c) + 4 n = InStrB(m + 1, b, LeftB(b, d - 1)) - m - 2 ' 获取文件扩展名 hh = LCase(Mid(h, InStrRev(h, ".") + 1)) If hh = "" Then hh = "jpg" ' 生成时间格式的文件名 currentTime = Now() formattedTime = Year(currentTime) & Right("0" & Month(currentTime), 2) & Right("0" & Day(currentTime), 2) & "_" & Right("0" & Hour(currentTime), 2) & Right("0" & Minute(currentTime), 2) & Right("0" & Second(currentTime), 2) ' 加上毫秒避免重复(使用Timer) Dim msPart msPart = Int((Timer * 1000) Mod 1000) msPart = Right("00" & msPart, 3) formattedTime = formattedTime & "_" & msPart fileName = formattedTime & "." & hh ' 保存文件 f.Type = 1 f.Open a.Position = i - 1 a.CopyTo f, j ' 确保upload目录存在 savePath = Server.MapPath(upload_folder) Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(savePath) Then fso.CreateFolder(savePath) End If Set fso = Nothing fullPath = savePath & "\" & fileName f.SaveToFile fullPath, 2 f.Close ' 清理 Set f = Nothing a.Close Set a = Nothing ' 返回成功JSON If Err.Number = 0 Then Response.ContentType = "application/json" Response.Write "{""success"":true,""filename"":""" & fileName & """}" Else Response.ContentType = "application/json" Response.Write "{""success"":false,""message"":""保存文件失败: " & Err.Description & """}" End If End Sub %>