asp自动采集程序

时间:2009-02-04 10:11:00 

<%
On Error Resume Next
Const uploadPath = "/uploads/" '文件存放路径
Const allowFileExt = "jpg,wma,swf,gif" '允许被采集的文件类型
'Const allowFileSize = "200"
Function getFile(url)
If url = "" Then
Exit Function
Else
url = Trim(url)
End If
'获取文件
fileExt = Lcase(Mid(url,Instrrev(url, ".")+1)) '文件类型
fileName = Lcase(Mid(url,Instrrev(url, "/")+1,Instrrev(url, ".")-Instrrev(url, "/")-1)) '无文件类型的文件名
newFilePath = getNow("Date") & "_" & Replace(FormatDateTime(Now(),3),":","") & "_" & cleanFileName(fileName) & "." & fileExt
if Instr(","&Lcase(allowFileExt)&",",","&fileExt&",") = 0 Then
getFile = "文件类型不允许"
Exit Function
End If
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
'While xmlhttp.readyState <> 4
' xmlhttp.waitForResponse 1000
'Wend
If xmlhttp.status <> 200 Then
getFile="获取文件出错"
Exit Function
Else
Set folder=Server.CreateObject("Scripting.FileSystemObject")
Dim folderName
folderName = getNow("Year")&getNow("Month") '文件夹
If folder.FolderExists(Server.MapPath(uploadPath))=False Then
folder.CreateFolder Server.MapPath(uploadPath)
End If
If folder.FolderExists(Server.MapPath(uploadPath & folderName))=False Then
folder.CreateFolder Server.MapPath(uploadPath & folderName)
End If
Set folder=Nothing
file=xmlhttp.ResponseBody
If lenb(file) > allowFileSize Then
getFile = "文件太大,不能保存!"
Exit Function
Else
Set objAdostream=Server.Createobject("ADODB.Str"&"eam")
objAdostream.Open()
objAdostream.Type=1
objAdostream.Write(file)
objAdostream.SaveToFile(Server.Mappath(uploadPath & folderName &"/" & newFilePath))
objAdostream.SetEOS
Set objAdostream=Nothing
getFile= "<a href="""&uploadPath & folderName &"/" & newFilePath&""" target=""_balnk"">采集成功</a>"
End If
End If
Set xmlhttp=Nothing
End Function
%>
<script runat="server" language="jscript">
function cleanFileName(str){
str = str.replace(/[^_\.a-zA-Z\d]/ig,"");
str = str.replace(/^[\/\.]+/,"");
return str;
}
function getNow(n)
{
d = new Date();
switch (n)
{
case "Year":
return d.getYear();
case "Month":
return (d.getMonth() + 1);
case "Date":
return d.getDate();
}
}
</script>
<%if request("do")="getfile" and request("file") <> "" then
response.write(getFile(request("file")))
else%>
<form id="gform" method="post" action="?do=getfile" style="display: inline">
<input name="file" type="input" style="font-size:12px;" size="40" value="http://blog.xiaobin.net/uploads/200512/08_093616_01.gif">
<input type="Submit" name="Submit" value="采集 " class="button">
</form>
<%end if%>

标签:采集,xmlhttp,ADODB,asp
0
投稿

猜你喜欢

  • 利用OpenCV给彩色 图像添加椒盐噪声的方法

    2023-06-15 00:11:30
  • vux-scroller实现移动端上拉加载功能过程解析

    2024-05-09 10:42:21
  • 常用的数据库访问方式是什么?

    2009-11-01 15:08:00
  • python读取TXT每行,并存到LIST中的方法

    2023-08-09 06:09:20
  • pandas DataFrame运算的实现

    2021-06-02 21:08:22
  • Python中使用logging和traceback模块记录日志和跟踪异常

    2023-09-20 16:08:51
  • 修复 Mac brew 安装 mongodb 报 Error: No available formula with the name ‘mongodb’ 问题详解

    2024-01-18 17:10:50
  • CentOS 7上为PHP5安装suPHP的方法(彭哥)

    2024-03-24 23:34:12
  • 命令行运行Python脚本时传入参数的三种方式详解

    2021-11-30 00:16:08
  • 解决pytorch报错:AssertionError: Invalid device id的问题

    2021-05-15 16:13:42
  • Python Json数据文件操作原理解析

    2022-10-27 19:00:32
  • jQuery 1.4官方中文手册[译]

    2010-01-20 10:46:00
  • 如何用Python画一些简单形状你知道吗

    2021-06-23 06:56:13
  • 如何使用表单发送电子邮件?

    2010-05-16 15:13:00
  • 白话Block Formatting Context

    2010-08-03 12:36:00
  • pyqt5 实现工具栏文字图片同时显示

    2023-08-12 17:46:58
  • 为什么首页最后设计

    2009-07-17 19:03:00
  • ubuntu下搭建Go语言(golang)环境

    2024-05-11 09:08:47
  • GoFrame基于性能测试得知grpool使用场景

    2024-05-08 10:52:24
  • python3模拟实现xshell远程执行linux命令的方法

    2022-05-26 11:45:14
  • asp之家 网络编程 m.aspxhome.com