Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASPJpeg and ASPUpload Issues

Status
Not open for further replies.

DynaCube

Programmer
Mar 19, 2007
1
US
Can someone please show me how to do this?

I currently have a form that is shown to the user after they login. It allows them to add data to several fields in the images table of my Access database. This data describes the image they are uploading and there is also a field for them to upload the image. This works fine. I have the ASP set to scale the image at 8% for the thumbnail. The user is not very computer savvy and does not want an involved process and is not comfortable with resizing the images.

This is what I need to do:

I'd like to continue to use the same form so the user does not notice a difference in using the system. I received a response from Persits and they stated it is possible to accomplish this, but they offered no help as to how to do it.

I would like the user to fill out the form, select the photo to upload, then submit the form. Once they submit the form, I'd like it to upload the image to memory, scale the image to 600x450 pixels (not percentage as is the default), save the thumbnail and original to the database along with the image details they have entered.

I have used the same sample code which was provided in the ASPJpeg manual. The only thing I have changed is I have adapted my variables into the code, which work just fine. Here is the code I am using.

form2mem.asp
Code:
<HTML>
<HEAD>
<TITLE>Image Upload</TITLE>
</HEAD>
<BODY>

<!-- Image upload form. Notice the ENCTYPE attribute -->
<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="03_upload2mem.asp">
<TABLE CELLPADDING="3" CELLSPACING="0" BORDER="0" BGCOLOR="#EEEEEE">
<TR><TD>Image:</TD><TD><INPUT TYPE=FILE NAME="MyFile"></TD></TR>
<TR><TD>Thumbnail Size:</TD><TD>
<SELECT NAME="scale">
<OPTION VALUE="75">75%
<OPTION VALUE="50">50%
<OPTION VALUE="25">25%
<OPTION VALUE="10">10%
</SELECT></TD></TR>
<TR><TD>Description:</TD><TD><TEXTAREA NAME="Description"></TEXTAREA></TD></TR>
<TR>
  <TD>Caption:</TD>
  <TD><input name="caption" type="text" id="caption"></TD>
</TR>

<TR><TD COLSPAN="2"><INPUT TYPE="SUBMIT" VALUE="Upload"></TD></TR>
</TABLE>
</FORM>

</BODY>
</HTML>


upload2mem.asp

Code:
<HTML>
<HEAD>
<TITLE>Image Upload</TITLE>
</HEAD>
<BODY>

<!-- this script is invoked by form2mem.asp-->
<%
    ' Create an instance of AspUpload object
    Set Upload = Server.CreateObject("Persits.Upload")

    ' Capture uploaded file, save to memory.
    Count = Upload.Save

    If Count = 0 Then
        Response.Write "No images selected. <A HREF=""03_form2mem.asp"">Try again</A>."
        Response.End
    Else

        ' Obtain File object representing uploaded file
        Set File = Upload.Files(1)

        ' Is this a valid image file?
        If File.ImageType <> "UNKNOWN" Then

            ' create instance of AspJpeg object
            Set jpeg = Server.CreateObject("Persits.Jpeg")
            
            ' open uploaded file from memory
            jpeg.OpenBinary( File.Binary )

            ' Using ADO, save both image and thumbnail in the database along with description.
            strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../db/aspjpeg.mdb")

            Set rs = Server.CreateObject("adodb.recordset")
            rs.Open "images", strConnect, 1, 3
            rs.AddNew
            
            ' Use Jpeg.Binary to access binary data. For now, it is the original image
            rs("original_image").Value = Jpeg.Binary

            ' resize image according to "scale" option.
            ' notice that we cannot use Request.Form, so we use Upload.Form instead.
            jpeg.Width = jpeg.OriginalWidth * Upload.Form("scale") / 100
            jpeg.Height = jpeg.OriginalHeight * Upload.Form("scale") / 100

            ' Now Jpeg contains a resized version of the original file. Save it too.
            rs("thumbnail").Value = Jpeg.Binary

            ' Obtain description from form using Upload.Form (not Request.Form)
            rs("description") = Upload.Form("Description")
            rs("caption") = Upload.Form("caption")

            rs.Update
            rs.Close
            Set rs = Nothing

            Response.Write "Success! Both the original file and its thumbnail are saved in the database.<P>"
        Else            
            Response.Write "This is not a valid image. <A HREF=""03_form2mem.asp"">Try again</A>."
            Response.End
        End If
    End If
%>
</BODY>
</HTML>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top