1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Rep Power

    How to change src of img in html file

    I have a page using which a user can upload a html file in his account to send it as a mailer to others. I need help to detect images on html file and replace the src of each to absolute path. I have regex to detect the img tab but not able to detect src value

    Filename = "albmailer.html" ' file to read
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

    ' Create a filesystem object
    Dim FSO
    set FSO = server.createObject("Scripting.FileSystemObject")

    ' Map the logical path to the physical system path
    Dim Filepath
    Filepath = Server.MapPath(Filename)

    if FSO.FileExists(Filepath) Then

    ' Get a handle to the file
    Dim file
    set file = FSO.GetFile(Filepath)

    ' Get some info about the file
    Dim FileSize
    FileSize = file.Size

    Response.Write "<p><b>File: " & Filename & " (size " & FileSize &_
    " bytes)</b></p><hr>"
    Response.Write "<pre>"

    ' Open the file
    Dim TextStream
    Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)

    ' Read the file line by line
    Do While Not TextStream.AtEndOfStream
    Dim Line
    Line = TextStream.readline

    ' Do something with "Line"
    Line = Line & vbCRLF

    'Response.write Line
    sOutput = sOutput&Line

    'Response.Write "</pre><hr>"

    Set TextStream = nothing


    Response.Write "<h3><i><font color=red> File " & Filename &_
    " does not exist</font></i></h3>"

    End If

    Set FSO = nothing

    sPattern = "<img[^>]*>"
    sPattern = "\<img\s[^\>]*?src=[""']([^""']*?\.(jpg|jpeg|bmp|gif|png)(\?[^""']*)?)[""'][^\>]*\>"
    set objReg = new regexp
    objReg.Pattern = sPattern
    objReg.IgnoreCase = true
    objReg.Global = true
    set sMatch = objReg.Execute(sOutput)
    for each match in sMatch

  2. #2
  3. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Rep Power
    I am also waiting for the reviews for the same topics and now i got the some information from your post. So, Please keep sharing your Discussion. Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo