关于正则的问题,正则高手请进,谢谢!(已解决)[动网官方论坛] - 已使用 Google 工具栏发送

0 views
Skip to first unread message

st w

unread,
Mar 25, 2008, 1:02:52 PM3/25/08
to wst, ea...@googlegroups.com
关于正则的问题,正则高手请进,谢谢!(已解决)[动网官方论坛]


远程图片可以,本地图片不可以。

如果本地图片也可以,那就可以在后台自动上传用户电脑中的任意文件了。

objregEx.Pattern = "src="& chr(34) &"http://(.+?)\.("& FileSaveType &")" '查找远程文件

这是我从我的程序中复制来的,可用,其中FileSaveType是需要保存的文件后缀,

NetFileSaveType="jpg|gif|swf|png|GIF|JPG|SWF|PNG"

 

st w

unread,
Mar 25, 2008, 1:04:26 PM3/25/08
to wst, ea...@googlegroups.com

经过一上午的研究,终于搞定,用的编辑器是动网8.2以前的编辑器,可以输入网络上的图片地址,也可以在本地选择图片,保存文章的同时实现远程存图,

核心函数:

 

 '远程存图替换路径函数,函数中已经调用了远程存图函数
 Function ReplaceRemoteUrl(ArticleContent,SaveFilePath)
  Dim Re,FinallyArticleContent,RemoteFile,RemoteFileUrl,SaveFileName

   Set Re=New RegExp
    Re.IgnoreCase=True
    Re.Global=True
    Re.Pattern = "((http|https|file):(\/\/|\\\\|\/\/\/|\\\\\\){1}((\w)+[.|:]){1,}(net|com|cn|org|cc|tv|[0-9]{0,3})(\S*\/)((\S)+[.]{1}(gif|jpg)))"

   FinallyArticleContent=ArticleContent

    Set RemoteFile=Re.Execute(FinallyArticleContent)

   Set Re=Nothing

   For Each RemoteFileUrl In RemoteFile
    SaveFileName=RndFileName()&Right(RemoteFileUrl,4)
    SavePic RemoteFileUrl,SaveFilePath,SaveFileName  '调用远程存图函数
    FinallyArticleContent=Replace(FinallyArticleContent,RemoteFileUrl,SaveFilePath&"/"&SaveFileName)
   Next

  ReplaceRemoteUrl=FinallyArticleContent

 End Function

 '远程存图函数
 Public Function SavePic(RemotePicUrl,LocalPicUrl,LocalPicName) 'RemotePicUrl  远程图片地址;  LocalPicUrl  图片保存相对路径;  LocalPicName  图片保存名称
  Dim XmlHttp,Img,ObjAdoStream,PicUpload,PicFile,AbsoluteLocalPicUrl

   AbsoluteLocalPicUrl=Server.MapPath(LocalPicUrl)

  Set XmlHttp=Server.CreateObject("Microsoft.XmlHttp")
   XmlHttp.Open "Get",RemotePicUrl,False
   XmlHttp.Send
   Img=XmlHttp.ResponseBody
  Set XmlHttp=Nothing

  Set ObjAdoStream=Server.CreateObject("ADODB.Stream")
   ObjAdoStream.Open()
   ObjAdoStream.Type=1
   ObjAdoStream.Write(Img)
   ObjAdoStream.SaveToFile(AbsoluteLocalPicUrl&"\"&LocalPicName)
   ObjAdoStream.SetEOS
  Set ObjAdoStream=Nothing

  Set PicUpload=Server.CreateObject("Persits.Upload")
   Set PicFile=PicUpload.OpenFile(AbsoluteLocalPicUrl&"\"&LocalPicName)

  If LCase(PicFile.ImageType)<>"jpg" and LCase(PicFile.ImageType)<>"gif" Then
   PicUpload.DeleteFile AbsoluteLocalPicUrl&"\"&LocalPicName
   Response.Write("图片格式错误!")
   Response.End()
  End If

  Set PicUpload=Nothing
   Set PicFile=Nothing
 End Function

Reply all
Reply to author
Forward
0 new messages