Wrox Programmer Forums
|
Classic ASP Components Discussions specific to components in ASP 3.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Components section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 19th, 2007, 12:43 AM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to DynaCube Send a message via AIM to DynaCube
Default ASPJpeg Issue

Can someone 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>


<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>


<%
    ' 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>





Similar Threads
Thread Thread Starter Forum Replies Last Post
upload multiple files in db with persits aspjpeg dann2 Classic ASP Basics 0 May 10th, 2007 11:20 PM
aspjpeg Adam H-W Classic ASP Components 4 October 29th, 2005 05:53 AM
Another issue islandtiu BOOK: Beginning ASP 3.0 1 February 14th, 2005 11:49 AM
Sub Report Issue bjoneskc01 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 January 21st, 2005 11:26 AM
deployment issue p_gauri7 Crystal Reports 0 January 19th, 2005 11:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.